![]() |
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: if ($today == "Sunday") { print (" ![]() } if ($today == "Monday") { print (" ![]() } if ($today == "Tuesday") { print (" ![]() } if ($today == "Wednesday") { print (" ![]() } if ($today == "Thursday") { print (" ![]() } if ($today == "Friday") { print (" ![]() } if ($today == "Saturday") { print (" ![]() } ?> 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 |huh |
You have the openinng php tag wrong.. it should be:
|
The first thing I see is your opening tag, you have
The second thing I see is that you could do things a little easier... Code:
|
Many thanks to iMan and cd34. That's saved me hours of work. :D |bananna|
|
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: for($i=0; $i<7; $i++){ if(date("w") == $i){ echo " ![]() }// 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 :) |
All times are GMT -4. The time now is 08:21 PM. |
Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© Greenguy Marketing Inc