You are here: Re: Using an IF statement « PHP SQL « IT news, forums, messages
Re: Using an IF statement

Posted by coder96 on 11/02/06 07:37

That sure would be a maintenance headache. Plus probly only get you a
minable grade. You need to get your data in a strucure of some kind.
Stop coding for the data at hand. It will change.

$Rec[0]['name'] = 'Period 1';
$Rec[0]['start'] = '9 AM';
$Rec[0]['stop'] = '9:59 AM';
$Rec[1]['name'] = 'Period 2';
$Rec[1]['start'] = '10AM';
$Rec[1]['stop'] = '10:59 AM';

$timenow = strtotime('now');

foreach ($Rec as $key){
if(strtotime($key['start']) =< $timenow AND
strtotime($key['stop']) => $timenow){
$period = 'It is currently: '. $key['name'];
}
}
if(empty($period)){
$period = 'School is not currently in.';
}

On Thu, 2 Nov 2006 10:54:22 +1100, "Thomas Blake"
<thomasblake@NOSPAM.optusnet.com.au> wrote:

>Hi,
>I am trying to create an IF statement that will display a message for a
>school (depending on the time of day) as to what period / class it is.
>
>The class times are:
>Period 1: 9 AM - 9:59 AM
>Period 2: 10 AM - 10:59 AM
>Recess: 11 AM - 11:29 AM
>Period 3: 11:30 AM - 12:29 PM
>Period 4: 12:30 PM - 1:29 PM
>Lunch: 1:30 PM - 1:59 PM
>Period 5: 2:00 PM - 3:00 PM
>
>What I have so far is:
>
>$todayhour = date("h"); // displays 09, 10, 11 etc
>$todayminute = date("i"); // displays the minute 01, 11, 25 etc
>$todayampm = date("A"); // displays AM or PM
>
> if ($todayhour == "09" AND $todayampm == "AM" )
> {
> $period = "It is currently Period 1";
> }
> elseif ($todayhour == "10" AND $todayampm == "AM" )
> {
> $period = "It is currently Period 2";
> }
> elseif ($todayhour == "12" AND $todayampm == "PM" )
> {
> $period = "It is currently Period 3";
> }
> elseif ($todayhour == "01" AND $todayampm == "PM" )
> {
> $period = "It is currently Period 4";
> }
> elseif ($todayhour == "02" AND $todayampm == "PM" )
> {
> $period = "It is currently Period 5";
> }
> else
> {
> $period = "School is not currently in";
> }
> ?>
>
>This program works to a certain extent, I am unsure how to incorporate
>things such as recess and lunch that go from 11:00 - 11:29 and 1:30 - 1:59
>
>Any help would be greatly appreciated
>
>Thanks,
>Tom
>
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация