NameSilo

PHP if Else - Please help 100NP's

Spaceship Spaceship
Watch

emadiba

VIP Member
Impact
3
Hi there Guys,

Im stuck on something very basic and actually feel quite embarrassed...lol

I need some help in what im doing wrong here.

<?php
$hour = $_GET['hours'];
$min = $_GET['mins'];
$sec = $_GET['secs'];
$time = '$hour:$min:$sec';

if($time >= 07:00:00 && <= 18:59:59){
$shift = Days;
}
else {
$shift = Nights;
}

?>

Basically what im trying to do is say that if the time is between 07:00:00 and 18:59:59 then Hold the term Days as a variable, otherwise hold the term Nights.

Can Someone Please help me out

:-/ :-/ :-/ :-/ :-/

Thanks.... 100NP's To The First Person that Helps me


:)
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
You just need to check $hour like you only want to test if hour is between 7 and 18 including.

Here the code.

Code:
<?php 
$hour = $_GET['hours'];
$min = $_GET['mins'];
$sec = $_GET['secs'];
$time = '$hour:$min:$sec';

if($hour >= 7 && $hour <= 18 ){
$shift = 'Days';
}
else {
$shift = 'Nights';
}

echo $shift;

?>
Hope that helps.
David.
 
0
•••
Thanks that did help,

NP's Sent

:)

Silly Mistake wasnt it....lol
 
1
•••
Donation greatly appreciated Clayton.

Thanks,
David.
 
0
•••
Just a small note since I see you're in to $_GET, etc.: If register_globals is on, you won't need to use $_GET or $HTTP_GET_VARS. If I type:

somescript.php?blah=blah02

and register_globals is on, $blah would contain "blah02" (without the quotes)
 
0
•••
just because that works EKukiela101 does not mean it should be used.

Register globals is a bad thing and should be turned off wherever possible
 
0
•••
0
•••
It's a security risk to turn register_globals on, and php recommends that register_globals should be set to off always. I believe most web hosts do not have this option turned on.
 
0
•••
Hi,

Just asking why not use the strftime() function easier to deal with and program.
 
0
•••
use the strftime() function like strftime("%c %p");
the %c tell you the time and date and the %p tell you the am pm bit,
you could also use %X instead of the %c.

Hope this has been helpful.............
 
0
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back