Jump to content

I know how to display today's mysql records, but how about the next 7 or 30 days


jcsickz

Recommended Posts

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?

 

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");

 

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.