Reputation: 1
I'm working on a blog-like event calendar which displays the upcoming events. Past events don't show up anymore. Everything works fine, however I want to limit the number of records to let's say 10 per page, then click to go the next set.
Now I have this:
<?php
$past = strtotime('now');
$result = mysql_query("SELECT * FROM data ORDER BY '$thedate' ASC LIMIT 0,10");
while($row = mysql_fetch_object($result))
{
$end_event_date = $row->end_strtotime;
if($end_event_date > $past) {
//display data
The problem is that the past events are still "calculated" in this list, depending on their id's, and if they're in the past as desired they don't show up. So instead of 10 records, perhaps only 3 or 7 show. What can I do to actually display the 10 next events, sorted by date, regardless of their id's? Thanks for any hints...
Upvotes: 0
Views: 61
Reputation: 5105
Just filter the events that are in the past in the query. That makes your code easier and solves your problem. Try this:
<?php
$past = strtotime('now');
$result = mysql_query("SELECT * FROM data WHERE end_event_date > NOW() ORDER BY '$thedate' ASC LIMIT 0,10");
while($row = mysql_fetch_object($result))
{
//display data
You might have to change the field name end_event_date
though if it's called different in your database.
Note: please don't use the mysql_*
functions anymore. They are deprecated. Use mysqli_*
or PDO
instead.
Upvotes: 1