-1

Am trying to display information on a website based on the local time. Each element has 3 elements.

1. A start time from 01 - 24
2. An end time from 00 - 60
3. A day of the week from Mon - Sun

What I want to do is load a specific element from the database, based on the day and time. How do I go about it? Is there any scripts to do this in php/mysql?

I've managed to get all the elements from the database to load based on the day, using the script below;

<? 

$day = date('l');  // weekday name (lower-case L) 
$time = (int)date("Gi");

$getdays = mysql_query("SELECT * FROM pages WHERE title = '".$day."'"); $getdays = mysql_fetch_array($getdays);
$getonair = mysql_query("SELECT * FROM pages WHERE subnav LIKE '%".$getdays['id']."%' AND type = '10'"); 

while ($goa = mysql_fetch_array($getonair)) {   

?><? echo $goa['id']; ?> - <? echo $goa['content']; ?></div>
<? } ?>

This currently will display all the elements in the database for today with their start and end times i.e.

item 1
start time: 1700
end time: 1730
content: some content here

item 2
start time: 1400
end time: 1430
content: some content here

item 3
start time: 0400
end time: 1430
content: some content here

item 4
start time: 1800
end time: 1830
content: some content here

item 5
start time: 2200
end time: 2230
content: some content here

What I now need to do is figure out a way to select the right item and display it based on the current time. How do I do this???

Jay Smoke
  • 573
  • 3
  • 13
  • 35

1 Answers1

0

OK after cracking my brains and going through some articles, I figured out a way to make it work and it's quite simple. Check the query below for more details.

<? 

$day = date('l');  // weekday name (lower-case L) 
$time = (int)date("Gi");

$getdays = mysql_query("SELECT * FROM pages WHERE title = '".$day."'"); $getdays =   
mysql_fetch_array($getdays);
$getonair = mysql_query("SELECT * FROM pages WHERE subnav LIKE '%".$getdays['id']."%'
`content` <= '".$time."' AND `caption` >= '".$time."' AND type = '10'"); 

while ($goa = mysql_fetch_array($getonair)) {   

?><? echo $goa['id']; ?> - <? echo $goa['content']; ?></div>
<? } ?>
Jay Smoke
  • 573
  • 3
  • 13
  • 35