How to Structure this Script
Moderator: General Moderators
How to Structure this Script
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.
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.
you would structure it something like:
Hope that helps you 
-wyrmmage
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>-wyrmmage
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
?>
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.
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?
Code: Select all
case '> 01012006 AND < 02102006':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
(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!';
}- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
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()Thoth wrote:Code: Select all
<?php $month = getdate(); switch($month) { case '01012006 && < 02102006': echo'The month is January!'; }
breaks and defaults aren't requirements eitherhmmm...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
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
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.
No he doesn't.hmmm...can't really tell you much. you need to have ?> at the end of your php page
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Code: Select all
error_reporting(E_ALL);
ini_set('display_errors', TRUE);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
And yes, you could use pairs of
Code: Select all
if()
{
}
else if()
{
}
else()
{
}-wyrmmage