Welcome to WebmasterWorld Guest from 54.162.226.212

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)

10+ Year Member



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 Jul 6, 2013 (gmt 0)

10+ Year Member



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 Jul 6, 2013 (gmt 0)

10+ Year Member



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

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

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



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month