I have a table with many two columns: id, mydate
- Id is a number;
- mydate is datetime like: 2011-02-10 09:25:02
I have 10 record in this table. 8 record have ID=1111 and two ID=2222
The two rows in the database:
id mydate
2222 2011-02-10 09:25:02
2222 2011-02-09 18:44:08
When the page is load, I want to check my table specifically for an ID and if the difference between the DATE of this IDs and the current DATE is bigger then X days then I want to update that record.
I try something like this:
$X=1;
$query = "SELECT id FROM testtable WHERE id='2222' AND mydate > DATE_SUB(NOW(), INTERVAL $X DAY)";
$result = mysql_query($query) or die("something went wrong..");
$test= array();
if (mysql_num_rows($result) > 0) {
$i = 0;
while($test[$i] = mysql_fetch_array($result)) {
$i++;
}
}
echo "the number of rows is:".$i;
But with this $i is empty.If i change $X=2 then i got 2 in echo. I don’t understand.
The current server date is: Friday 11th of February 2011 11:41:51
Instead of
DATE_SUB(NOW(), useDATE_SUB(CURDATE()to go to midnight today.