Page 1 of 1
How to Structure this Script
Posted: Tue Dec 05, 2006 5:35 pm
by Thoth
Forgive me in advance if the question is rather vague, I will attempt to make it as clear as possible. I wanted to make my first PHP script and need help with the general form, or 'how to do it'. I have read a lot of beginner tutorials but am kind of confused on the whole process.
I want the script to display a text and photo for the sun in it's zodiacal position for each of the 12 months.
For example, today is Tuesday, December 5th, 2006.
Sun's Tropical Zodiac position is Sagittarius the Archer (From Wednesday, November 22nd 2006 to Wednesday, December 20th 2006). So anytime between Nov 22nd and Dec 20th, the script would display a message.
I hope this is somewhat clear, if you need any more info please ask.
Posted: Tue Dec 05, 2006 8:30 pm
by wyrmmage
you would structure it something like:
Code: Select all
<HTML>
<HEAD>
<TITLE>Whatever The Title</TITLE>
</HEAD>
<BODY>
<?php
//index.php
$month = //get your month here;
switch($month)
{
case 'January':
echo'The month is January!';
echo'<IMG SRC="whateverTheSource.gif (or jpg, bmp, or whatever)">';
break;
case 'February':
//do whatever here
break;
//repeat for the rest of the months, and then:
default:
echo'Unrecognized month!';
break;
}
//You can add some text that will always be seen down here
?>
</BODY>
</HTML>
Hope that helps you

-wyrmmage
Posted: Tue Dec 05, 2006 8:47 pm
by Zoxive
I'd much rather use
Code: Select all
<?php
print 'Today is ' . date("L, F jS, Y");
// outputs: Today is Tuesday, December 5th, 2006
?>
Posted: Tue Dec 05, 2006 9:09 pm
by Thoth
Thanks for the quick responses! I finally have some foundation to work with. I see where the snag will be though. Some months zodiacs transfer over in the middle of the month. I'm sure there is an easy method, but I seem to missing something. I get how to do a message for each of the 12 months now which is a start.
Posted: Tue Dec 05, 2006 9:43 pm
by 4Boredom
I dont know how exactly your doing your date formula, but it would be...
Or something like that if you can break the date feature into a formula like that?
Posted: Tue Dec 05, 2006 9:47 pm
by Thoth
I wanted to test out the script and start easy. I tried to load it and just a white screen came up. I got an error in my apache logs, but all the other php scripts are working.
(OS 996)Overlapped I/O event is not in a signaled state. : winnt_accept: Asynchronous AcceptEx failed.could
Code: Select all
<?php
$month = getdate();
switch($month)
{
case '01012006 && < 02102006':
echo'The month is January!';
}
Posted: Tue Dec 05, 2006 11:05 pm
by wyrmmage
hmmm...can't really tell you much. you need to have ?> at the end of your php page, though, and you need to have break; after each casestatement. I think you have to have a default: case, also (along with a break; statement after it).
-wyrmmage
Posted: Tue Dec 05, 2006 11:19 pm
by John Cartwright
Thoth wrote:
Code: Select all
<?php
$month = getdate();
switch($month)
{
case '01012006 && < 02102006':
echo'The month is January!';
}
You can't evaluate logic like that in a string.. it is actually trying to match against the string not the logic. You'll have to use if(), elseif(), and else() statements. Secondly, getdate() returns an associative array of date values, and not a string like you have set it up. Instead, use date()
hmmm...can't really tell you much. you need to have ?> at the end of your php page, though, and you need to have break; after each case statement. I think you have to have a default: case, also (along with a break; statement after it).
-wyrmmage
breaks and defaults aren't requirements either
Posted: Wed Dec 06, 2006 5:10 am
by Ollie Saunders
I think switchfever is going down in devnet. There is absolutely no need for a switch in this code. What is more you are attempting to use it incorrectly as Jcart has explained.
hmmm...can't really tell you much. you need to have ?> at the end of your php page
No he doesn't.
Posted: Wed Dec 06, 2006 5:19 am
by CoderGoblin
Code: Select all
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
Good practice while developing is to include the above... These two commands in your php will show errors unless they are fatal errors (produce simply a white page <html></html>). Once your code is complete/working without a hitch you can delete or comment them out.
Posted: Wed Dec 06, 2006 8:02 am
by wyrmmage
meh, ok, ok, he doesn't actually HAVE to have all of those things, but since he's asking for advice o how to structure his code, I think that it would be a good idea that he put them in.....

And yes, you could use pairs of
statements; I always use the above instead of using switches.
-wyrmmage