Using the time to retrieve specific content from a database through php -
am trying display information on website based on local time. each element has 3 elements.
1. start time 01 - 24 2. end time 00 - 60 3. day of week mon - sun
what want load specific element database, based on day , time. how go it? there scripts in php/mysql?
i've managed elements database load based on day, using script below;
<? $day = date('l'); // weekday name (lower-case l) $time = (int)date("gi"); $getdays = mysql_query("select * pages title = '".$day."'"); $getdays = mysql_fetch_array($getdays); $getonair = mysql_query("select * pages subnav '%".$getdays['id']."%' , type = '10'"); while ($goa = mysql_fetch_array($getonair)) { ?><? echo $goa['id']; ?> - <? echo $goa['content']; ?></div> <? } ?>
this display elements in database today start , end times i.e.
item 1 start time: 1700 end time: 1730 content: content here item 2 start time: 1400 end time: 1430 content: content here item 3 start time: 0400 end time: 1430 content: content here item 4 start time: 1800 end time: 1830 content: content here item 5 start time: 2200 end time: 2230 content: content here
what need figure out way select right item , display based on current time. how do this???
ok after cracking brains , going through articles, figured out way make work , it's quite simple. check query below more details.
<? $day = date('l'); // weekday name (lower-case l) $time = (int)date("gi"); $getdays = mysql_query("select * pages title = '".$day."'"); $getdays = mysql_fetch_array($getdays); $getonair = mysql_query("select * pages subnav '%".$getdays['id']."%' `content` <= '".$time."' , `caption` >= '".$time."' , type = '10'"); while ($goa = mysql_fetch_array($getonair)) { ?><? echo $goa['id']; ?> - <? echo $goa['content']; ?></div> <? } ?>