Script doesn't recognize if open past 12:00 am
I have a script that looks at a database of hours for stores. The table is set up by ID, Day, Hour Open, Hour Closed. The time is in military hours, 1pm = 13:00:00 hours. Currently it doesn't work correctly. Wondering if anyone could just give me a pointer on how to fix the script.
date_default_timezone_set('America/New_York');
include 'connect.php';
$day = date('l');
$time = date('H:i:s');
$result=mysql_query("SELECT storehours.ID, store.ID, store.Name FROM storehours, store WHERE Day = '$day' AND '$time' BETWEEN Open AND Close AND storehours.ID = store.ID ORDER BY Name");
Thanks for any help
ptara1
Junior Poster in Training
67 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
What are your datatypes for Open and Close?
Variable Characters aka Varchar
ptara1
Junior Poster in Training
67 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
I messed around with the data type but that didn't help... Do I just need to add rows to the table? So for example:
If the store is open from 12:00:00 to 2:00:00 set up to rows..
One 12:00:00 to 23:59:59
and the other
00:00:01 to 2:00:00?
Is there an easier way to do this?
ptara1
Junior Poster in Training
67 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
$result=mysql_query("SELECT storehours.ID, store.ID, store.Name FROM storehours, store WHERE Day = '$day' AND '$time' BETWEEN Open AND Close AND storehours.ID = store.ID ORDER BY Name");
Does sql pass?
AND '$time' BETWEEN Open AND Close
what about?
...AND `Open` <= '$time' AND `Close` >= '$time'...
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
Thanks for those two responses. I tried to see how they would work and they don't appear to help. What I've been thinking would work is if I entered a clause in the sql statement that went something like this:
SELECT blah blah blah WHERE ('$time' BETWEEN Open AND Close AND Day = '$day' OR '$time' BETWEEN 00:00:00 AND Close AND DAY='$day'-1) AND hours.ID = store.ID ORDER BY Name
This doesn't work..but I don't know why. I think this is a logical way to do it.
ptara1
Junior Poster in Training
67 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0
SELECT blah blah blah WHERE ('$time' BETWEEN Open AND Close AND Day = '$day' OR '$time' BETWEEN 00:00:00 AND Close AND DAY='$day'-1) AND hours.ID = store.ID ORDER BY Name
Did you try running this in phpmyadmin? Bet it gave you an error.
diafol
Rhod Gilbert Fan (ardav)
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
Yeah it does. I didn't want to write out all the selects sorry...Will try the above suggestions. Thanks again.
SELECT blah blah blah WHERE ('$time' BETWEEN Open AND Close AND Day = '$day' OR '$time' BETWEEN 00:00:00 AND Close AND DAY='$day'-1) AND hours.ID = store.ID ORDER BY Name
Did you try running this in phpmyadmin? Bet it gave you an error.
ptara1
Junior Poster in Training
67 posts since Jul 2010
Reputation Points: 10
Solved Threads: 0