DDmUSA Posted May 2, 2011 Share Posted May 2, 2011 I would like to know the best practice to achieve the following: I have a list of dates related to live events for performing artists. When someone views the web page that contains a section to display the dates, I would only want to show the dates from today into the future and not show any dates from the past. What is the best way to accomplish this? Thanks in advance... Quote Link to comment https://forums.phpfreaks.com/topic/235333-limiting-display-of-dates-based-on-current-date/ Share on other sites More sharing options...
kney Posted May 2, 2011 Share Posted May 2, 2011 This is for when ur date are in db <?php $sql = mysql_query("SELECT date FROM table"); while($results == mysql_fetch_query($sql)){ if($results[0] > now()){ // show date echo $results[0]; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/235333-limiting-display-of-dates-based-on-current-date/#findComment-1209346 Share on other sites More sharing options...
Fadion Posted May 2, 2011 Share Posted May 2, 2011 The following queries will get only the rows with the date greater than the moment it's executed. NOW() -> datetime (2011-05-02 12:06:10) SELECT col1, col2 FROM table WHERE date>=NOW() CURDATE() -> date (2011-05-02) SELECT col1, col2 FROM table WHERE date>=CURDATE() Quote Link to comment https://forums.phpfreaks.com/topic/235333-limiting-display-of-dates-based-on-current-date/#findComment-1209350 Share on other sites More sharing options...
DDmUSA Posted May 2, 2011 Author Share Posted May 2, 2011 I do not have a database in place. Let's say I have a text file with one date per line. How would I fetch the lines of text (into an array, perhaps) and then display only the dates greater than moment executed? Quote Link to comment https://forums.phpfreaks.com/topic/235333-limiting-display-of-dates-based-on-current-date/#findComment-1209370 Share on other sites More sharing options...
Fadion Posted May 2, 2011 Share Posted May 2, 2011 That would quite more complicated and really slow, but it's easily accomplished. However, without giving us a few event lines, we can't give a proper working solution. PS: You should really opt for a database approach. It will be 100x easier to handle (inserts, updates, whatever). Quote Link to comment https://forums.phpfreaks.com/topic/235333-limiting-display-of-dates-based-on-current-date/#findComment-1209377 Share on other sites More sharing options...
DDmUSA Posted May 2, 2011 Author Share Posted May 2, 2011 The event is a seasonal thing that will only last for several dates. The sample web page that includes the dates is located here: http://mrpcweb.com/insiders/sample1/indexb.html Quote Link to comment https://forums.phpfreaks.com/topic/235333-limiting-display-of-dates-based-on-current-date/#findComment-1209395 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.