Welcome to WebmasterWorld Guest from 54.162.4.139

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP newbie - if statement "not working?"

Please help

     
3:51 am on Jul 6, 2013 (gmt 0)

Preferred Member

10+ Year Member

joined:May 23, 2002
posts: 446
votes: 0


Hi

I'm new to PHP and a (apparently easy) problem is driving me nuts.

I want to check the URL and display country relevant pictures. Simple.

When I run my script all the pictures are loaded!


<?php
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$actual_link = strtolower($actual_link);
$UseDefault = "1";

if (strpos($actual_link, 'country1') > 0)
$UseDefault = "0";
{ ?>
<img src="Image URL" alt="Image Alt" />
<img src="Image URL" alt="Image Alt" />
<img src="Image URL" alt="Image Alt" />
<?php
}
if (strpos($actual_link, 'country2') > 0)
$UseDefault = "0";
{ ?>
<img src="Image URL" alt="Image Alt" />
<img src="Image URL" alt="Image Alt" />
<img src="Image URL" alt="Image Alt" />
<?php
}
if ($UseDefault = "1")
{
if(get_cf_matrix('banner-image','45'))
{
foreach(get_cf_matrix('banner-image','45') as $image)
{ ?>
<img src="<?php echo $image->url; ?>" alt="<?php echo $image->alt; ?>" />
<?php
}
}
} ?>


In the above case all nine images are displayed! Scratching my head.

Thanks in advance.

Mick
4:43 am on July 6, 2013 (gmt 0)

Preferred Member

10+ Year Member

joined:May 23, 2002
posts: 446
votes: 0


Hmmmm...while re-reading my post I noticed a bug.

the $UseDefault = "0"; should be inside the {

I fixed that but the if ($UseDefault = "1") are always being displayed.

Nearly there!
4:49 am on July 6, 2013 (gmt 0)

Preferred Member

10+ Year Member

joined:May 23, 2002
posts: 446
votes: 0


<groan>
The if statement should have == not =
</groan>

Still learning!
5:16 am on July 6, 2013 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

joined:Apr 9, 2011
posts:13599
votes: 412


The if statement should have == not =

I believe this is my single most common error in javascript :) And the only reason it doesn't hold the same position among php errors is that I simply don't do enough of it.

I like the way you were able to solve your own problem after giving up and posting it publicly. Been there. Done that.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members