traumm Posted September 28, 2010 Share Posted September 28, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/214624-help-with-time-related-mysql-query-needed/ Share on other sites More sharing options...
fenway Posted September 29, 2010 Share Posted September 29, 2010 and eventTime is a TIME field? Quote Link to comment https://forums.phpfreaks.com/topic/214624-help-with-time-related-mysql-query-needed/#findComment-1117163 Share on other sites More sharing options...
traumm Posted September 30, 2010 Author Share Posted September 30, 2010 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"].''; } Quote Link to comment https://forums.phpfreaks.com/topic/214624-help-with-time-related-mysql-query-needed/#findComment-1117530 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.