Hilly_2004 Posted March 1, 2008 Share Posted March 1, 2008 Hi guys, I've searched through the forums, and haven't found anything that might help me. I have a field in a table called "Fixture_Date" with a 'date' type e.g. YYYY-MM-DD, does anyone know a select query that will select the next upcoming event based on the current date? Thanks for any help you can throw my way! Quote Link to comment https://forums.phpfreaks.com/topic/93901-displaying-closest-date-in-the-future/ Share on other sites More sharing options...
AndyB Posted March 1, 2008 Share Posted March 1, 2008 SELECT whatever_fields from table_name WHERE Fixture_Date>'$today' ORDER by Fixture_Date ASC LIMIT 1 $today = date("Y-m-d") of course Quote Link to comment https://forums.phpfreaks.com/topic/93901-displaying-closest-date-in-the-future/#findComment-481173 Share on other sites More sharing options...
Hilly_2004 Posted March 1, 2008 Author Share Posted March 1, 2008 Cheers! Works a treat. For anyone else wondering my script looks like: <?php //Load all fixtures from the database and then ORDER them by Date (nearest date displayed first) $today = date("Y-m-d"); $result = mysql_query("SELECT * FROM tbl_fixtures WHERE Fixture_Date > '$today' ORDER BY Fixture_Date ASC LIMIT 1", $connect); //Loop and Get All The Fixtures From The Database while($myrow = mysql_fetch_array($result)) { //Prints Results echo "<p class=\"ColumnTitle\">"; echo $myrow['Opponent']; echo "</p>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/93901-displaying-closest-date-in-the-future/#findComment-481195 Share on other sites More sharing options...
fenway Posted March 2, 2008 Share Posted March 2, 2008 Replace '$today' with NOW() or CURDATE() as applicable. Quote Link to comment https://forums.phpfreaks.com/topic/93901-displaying-closest-date-in-the-future/#findComment-481359 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.