Jump to content

Help with time-related MySQL query needed!


traumm

Recommended Posts

New to the forum - hoping someone here can shed some light on this..! I only dabble in MySQL and am stuck here.

 

I'm building a type of calendar which is to display a list of recurring daily events. Every day the events are identical, and top of the list is the next event. I've managed to achieve this with the following:

 

 

$currentTime = date("H:i:s", time());$getEvent = mysql_query("SELECT * FROM events WHERE eventTime >= '$currentTime' ORDER BY eventTime");while($row=mysql_fetch_array($getEvent)){        echo ''.$row["eventTime"].'  - '.$row["eventName"].'';}

 

 

My problem is that until the $currentTime reaches 00:00:00 the past events are not shown. Whereas I need them to be displayed at the bottom of the list once their time has passed, in a cyclical fashion.

 

For example, at 15:01:00 the event with a time of 15:00:00 should be bottom of the list ready for the following day, rather than being hidden from view altogether.

 

Hope this makes sense - many thanks in advance for your help!

Thanks for the reply - eventTime is a TIME field, yes - though I've managed to fix this... an easy solution I'd completely overlooked!

 

Posted below just in case anyone is wondering.

 

$currentTime = date("H:i:s", time());

$getEvent = mysql_query("SELECT * FROM events WHERE eventTime >= '$currentTime' ORDER BY eventTime");
while($row=mysql_fetch_array($getEvent))

{
        
echo ''.$row["eventTime"].'  - '.$row["eventName"].'';

}

$getPastEvent = mysql_query("SELECT * FROM events WHERE eventTime < '$currentTime' ORDER BY eventTime");
while($row2=mysql_fetch_array($getPastEvent))

{
        
echo ''.$row2["eventTime"].'  - '.$row2["eventName"].'';

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.