homepage Welcome to WebmasterWorld Guest from 54.225.1.70
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
PHP newbie - if statement "not working?"
Please help
giggle




msg:4590731
 3:51 am on Jul 6, 2013 (gmt 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

 

giggle




msg:4590738
 4:43 am on Jul 6, 2013 (gmt 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!

giggle




msg:4590739
 4:49 am on Jul 6, 2013 (gmt 0)

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

Still learning!

lucy24




msg:4590743
 5:16 am on Jul 6, 2013 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved