Reputation: 8083
I have several activities in my database, but I would like to hide the ones from the past, so I modified my MySQL request:
$sql = "SELECT * FROM tblAgenda WHERE date <= CURDATE() order by date ASC";
But it doesn't do a thing except giving errors. What's wrong?
Upvotes: 0
Views: 573
Reputation: 50592
It seems like you're not getting any results, so that is throwing errors. You always need to check for results before looping, you cannot just assume that every query will return something.
Also, if you want things from the present/future, your comparison operand is backward:
$sql = "SELECT * FROM tblAgenda WHERE date >= CURDATE() order by date ASC";
Putting it together:
$sql = "SELECT * FROM tblAgenda WHERE date >= CURDATE() order by date ASC";
$result = mysql_query($sql);
if (!$result) {
// do something to handle zero results here
} else {
// do your usual while... loop
while ($row = mysql_fetch_assoc($result)) {
// code for each result row
}
}
Upvotes: 1