jcsickz Posted April 18, 2007 Share Posted April 18, 2007 I have recently found out how to display today's records from mysql, but now I want to display the records for the next 7 days as well as records from the next 30 days. Here is my current code: <?php $today = date("Y-m-d"); echo "Event Listing for " . $today ?> <?php $con = mysql_connect("localhost","username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("jcsickz_mc", $con); $result = mysql_query("SELECT * FROM events WHERE date = '" . $today ."' ORDER BY date DESC"); echo "<table border='1'> <tr> <th>Date</th> <th>Time</th> <th>Venue</th> <th>Description</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['date'] . "</td>"; echo "<td>" . $row['time'] . "</td>"; echo "<td>" . $row['venue'] . "</td>"; echo "<td>" . $row['description'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> how can I modify this code to display the next 7 days and the next 30 days? Link to comment https://forums.phpfreaks.com/topic/47641-i-know-how-to-display-todays-mysql-records-but-how-about-the-next-7-or-30-days/ Share on other sites More sharing options...
per1os Posted April 18, 2007 Share Posted April 18, 2007 Events just on the seventh day $next7 = date('Y-m-d', time()+3600*24*7); $result = mysql_query("SELECT * FROM events WHERE date = '" . $next7 ."' ORDER BY date DESC"); For all events up till the next 7 days $today = date('Y-m-d', time()); $next7 = date('Y-m-d', time()+3600*24*7); $result = mysql_query("SELECT * FROM events WHERE date BETWEEN '" . $today ."' AND '" . $next7 . "' $ORDER BY date DESC"); Link to comment https://forums.phpfreaks.com/topic/47641-i-know-how-to-display-todays-mysql-records-but-how-about-the-next-7-or-30-days/#findComment-232658 Share on other sites More sharing options...
jcsickz Posted April 18, 2007 Author Share Posted April 18, 2007 that code was perfect with the exception of the $ in front of ORDER. solved, thanks Link to comment https://forums.phpfreaks.com/topic/47641-i-know-how-to-display-todays-mysql-records-but-how-about-the-next-7-or-30-days/#findComment-232712 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.