How to Structure this Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Thoth
Forum Newbie
Posts: 3
Joined: Tue Dec 05, 2006 5:19 pm

How to Structure this Script

Post 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.
wyrmmage
Forum Commoner
Posts: 56
Joined: Sat Oct 28, 2006 12:43 pm
Location: boise, ID

Post 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
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

I'd much rather use

Code: Select all

date();

Code: Select all

<?php
print 'Today is ' . date("L, F jS, Y");
// outputs: Today is Tuesday, December 5th, 2006
?>
Thoth
Forum Newbie
Posts: 3
Joined: Tue Dec 05, 2006 5:19 pm

Post 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.
4Boredom
Forum Contributor
Posts: 176
Joined: Tue Nov 08, 2005 4:29 pm

Post by 4Boredom »

I dont know how exactly your doing your date formula, but it would be...

Code: Select all

case '> 01012006 AND < 02102006':
Or something like that if you can break the date feature into a formula like that?
Thoth
Forum Newbie
Posts: 3
Joined: Tue Dec 05, 2006 5:19 pm

Post 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!';
}
wyrmmage
Forum Commoner
Posts: 56
Joined: Sat Oct 28, 2006 12:43 pm
Location: boise, ID

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post 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.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post 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.
wyrmmage
Forum Commoner
Posts: 56
Joined: Sat Oct 28, 2006 12:43 pm
Location: boise, ID

Post 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..... :P
And yes, you could use pairs of

Code: Select all

if()
{
}
else if()
{
}
else()
{
}
statements; I always use the above instead of using switches.
-wyrmmage
Post Reply