|
|
|
|
|
|
![]() |
#1 |
I Love Turkish Delight, they're very moreish.
Join Date: Nov 2004
Location: UK
Posts: 578
|
Basic PHP Problem
I'm trying to teach myself PHP and I'm getting tied up in knots.
I'm trying to use conditionals to create a pic of the day script. I know it should be easy but my cocked result can be seen under the first banner at: http://www.jpmr1.com/index.html The code I'm using is: <php? $today = date("l"); if ($today == "Sunday") { print ("<img src=\"http://www.japamor.com/banners/ferrocash/sfs/200x250_001.gif\">"); } if ($today == "Monday") { print ("<img src=\"http://www.japamor.com/banners/ferrocash/sfs/200x250_002.gif\">"); } if ($today == "Tuesday") { print ("<img src=\"http://www.japamor.com/banners/ferrocash/sfs/200x250_003.gif\">"); } if ($today == "Wednesday") { print ("<img src=\"http://www.japamor.com/banners/ferrocash/sfs/200x250_004.gif\">"); } if ($today == "Thursday") { print ("<img src=\"http://www.japamor.com/banners/ferrocash/sfs/200x250_005.gif\">"); } if ($today == "Friday") { print ("<img src=\"http://www.japamor.com/banners/ferrocash/sfs/200x250_006.gif\">"); } if ($today == "Saturday") { print ("<img src=\"http://www.japamor.com/banners/ferrocash/sfs/200x250_001.gif\">"); } ?> I've spent hours trying to see what I've done wrong and its very frustrating. If anyone can help I'll be most grateful. Cheers ![]()
__________________
![]() |
![]() |
![]() |
![]() |
#2 |
Lord help me, I'm just not that bright
Join Date: Jun 2006
Location: Los Angeles
Posts: 101
|
You have the openinng php tag wrong.. it should be: <?php
|
![]() |
![]() |
![]() |
#3 |
a.k.a. Sparky
Join Date: Sep 2004
Location: West Palm Beach, FL, USA
Posts: 2,396
|
The first thing I see is your opening tag, you have <php? where it should be <?php
The second thing I see is that you could do things a little easier... Code:
<?php $banner_array = array( 'Sunday' => 'http://www.japamor.com/banners/ferrocash/sfs/200x250_001.gif', 'Monday' => 'http://www.japamor.com/banners/ferrocash/sfs/200x250_002.gif', 'Tuesday' => 'http://www.japamor.com/banners/ferrocash/sfs/200x250_003.gif', 'Wednesday' => 'http://www.japamor.com/banners/ferrocash/sfs/200x250_004.gif', 'Thursday' => 'http://www.japamor.com/banners/ferrocash/sfs/200x250_005.gif', 'Friday' => 'http://www.japamor.com/banners/ferrocash/sfs/200x250_006.gif', 'Saturday' => 'http://www.japamor.com/banners/ferrocash/sfs/200x250_001.gif' ); $today = date("l"); ?> html here <p> <img src="<?php echo $banner_array[$today];?>">
__________________
SnapReplay.com a different way to share photos - iPhone & Android |
![]() |
![]() |
![]() |
#4 |
I Love Turkish Delight, they're very moreish.
Join Date: Nov 2004
Location: UK
Posts: 578
|
Many thanks to iMan and cd34. That's saved me hours of work.
![]() ![]()
__________________
![]() |
![]() |
![]() |
![]() |
#5 | |
Lord help me, I'm just not that bright
Join Date: Jun 2006
Location: Los Angeles
Posts: 101
|
Hey japamor,
Quote:
It's usually the "little" things that takes time. And if you're just learning PHP, and don't know any other C type of language, some of the most common mistakes, besides the php tags, are: To not put a semi colon a the end of a line, mixing up equal operator (== and/or ===) with assignment operator (=), using a bitwise operator (&, |) when you intend to use a boolean operator (&&, ||). There are of course more... but I think these are the most common little buggers that you should pay attention to ![]() Btw, although I totally agree with cd34, here's a "quick and dirty" way to do the daily photo: <?php for($i=0; $i<7; $i++){ if(date("w") == $i){ echo "<img src='http://www.japamor.com/banners/ferrocash/sfs/200x250_00$i.gif'>"; }// if }// for ?> This requires your pictures to be named in a sequential way though.. with 0,1,2,3.. etc. where the $i is in the "img src" tag. Many ways lead to Rome, happy coding ![]() |
|
![]() |
![]() |
![]() |
|
|