Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

PHP IF/ELSE

Participant ,
Sep 05, 2008 Sep 05, 2008

Copy link to clipboard

Copied

I have six thumbnails on a page and a large image. On clicking the thumbnail the thumbnail reloads the page with a URL variable 'photo' which then becomes the enlarged image source. All of that works perfectly at the moment.

However, the first time the page is loaded the URL variable 'photo' is not present so I'm trying to use IF/ELSE to automatically make it show 'photo 1' if URL variable 'photo' is not present.

Unfortunately I just can't make it work. The image source returns blank when no URL variable is present instead of defaulting to $row_rs_properties['photo1']

Can anyone suggest why this code doesn't work?

Dave
TOPICS
Server side applications

Views

323
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 05, 2008 Sep 05, 2008

Copy link to clipboard

Copied

$photo = isset($_GET['photo'])?$_GET['photo']:'photo1';
$photo=($row_rs_properties[$photo]);

Make sure that this comes AFTER the recordset.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"davecheet" <webforumsuser@macromedia.com> wrote in message
news:g9r2sb$os4$1@forums.macromedia.com...
>I have six thumbnails on a page and a large image. On clicking the
>thumbnail
> the thumbnail reloads the page with a URL variable 'photo' which then
> becomes
> the enlarged image source. All of that works perfectly at the moment.
>
> However, the first time the page is loaded the URL variable 'photo' is not
> present so I'm trying to use IF/ELSE to automatically make it show 'photo
> 1' if
> URL variable 'photo' is not present.
>
> Unfortunately I just can't make it work. The image source returns blank
> when
> no URL variable is present instead of defaulting to
> $row_rs_properties['photo1']
>
> Can anyone suggest why this code doesn't work?
>
> Dave
>
> <?php
> //set photo variable if URL variable is present
> if(isset($_GET['photo']))
> {
> $photo=($_GET['photo']);
> }
> // set photo variable to photo 1 if URL variable is not present
> else{
> $photo=($row_rs_properties['photo1']);
> }
> ?>
>
> //main image source uses $photo
> <img src="images/propertyimages/<?php echo $photo; ?>"
>

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 05, 2008 Sep 05, 2008

Copy link to clipboard

Copied

Thanks Murray,

I pasted in your code after the recordset (and deleted my own) but still a blank result for the main image source. But now a blank return even when the URL variable is present.

Dave

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 05, 2008 Sep 05, 2008

Copy link to clipboard

Copied

Let's see the whole thing, please.

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"Murray *ACE*" <forums@HAHAgreat-web-sights.com> wrote in message
news:g9r5qb$rpn$1@forums.macromedia.com...
> $photo = isset($_GET['photo'])?$_GET['photo']:'photo1';
> $photo=($row_rs_properties[$photo]);
>
> Make sure that this comes AFTER the recordset.
>
> --
> Murray --- ICQ 71997575
> Adobe Community Expert
> (If you *MUST* email me, don't LAUGH when you do so!)
> ==================
> http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
> http://www.dwfaq.com - DW FAQs, Tutorials & Resources
> ==================
>
>
> "davecheet" <webforumsuser@macromedia.com> wrote in message
> news:g9r2sb$os4$1@forums.macromedia.com...
>>I have six thumbnails on a page and a large image. On clicking the
>>thumbnail
>> the thumbnail reloads the page with a URL variable 'photo' which then
>> becomes
>> the enlarged image source. All of that works perfectly at the moment.
>>
>> However, the first time the page is loaded the URL variable 'photo' is
>> not
>> present so I'm trying to use IF/ELSE to automatically make it show 'photo
>> 1' if
>> URL variable 'photo' is not present.
>>
>> Unfortunately I just can't make it work. The image source returns blank
>> when
>> no URL variable is present instead of defaulting to
>> $row_rs_properties['photo1']
>>
>> Can anyone suggest why this code doesn't work?
>>
>> Dave
>>
>> <?php
>> //set photo variable if URL variable is present
>> if(isset($_GET['photo']))
>> {
>> $photo=($_GET['photo']);
>> }
>> // set photo variable to photo 1 if URL variable is not present
>> else{
>> $photo=($row_rs_properties['photo1']);
>> }
>> ?>
>>
>> //main image source uses $photo
>> <img src="images/propertyimages/<?php echo $photo; ?>"
>>
>

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Sep 05, 2008 Sep 05, 2008

Copy link to clipboard

Copied

You were right though. I just reinstated my code but moved it to after the recordset and now it works like a swiss watch.

Problem Solved.

Thanks Murray

Dave

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 05, 2008 Sep 05, 2008

Copy link to clipboard

Copied

LATEST
Excellent. I was scratching my head for explanations if that had not been
the case! 8)

--
Murray --- ICQ 71997575
Adobe Community Expert
(If you *MUST* email me, don't LAUGH when you do so!)
==================
http://www.projectseven.com/go - DW FAQs, Tutorials & Resources
http://www.dwfaq.com - DW FAQs, Tutorials & Resources
==================


"davecheet" <webforumsuser@macromedia.com> wrote in message
news:g9r8au$134$1@forums.macromedia.com...
> You were right though. I just reinstated my code but moved it to after the
> recordset and now it works like a swiss watch.
>
> Problem Solved.
>
> Thanks Murray
>
> Dave

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines