i have 29 rows in mytable with datetime(dt). I want to sort it in descending order
when i query the table it give the result starting from 28 (29 not given) and after 28 it starts from 1, 2….27 where
(1-27 datetime is 0000-00-00 00:00:00) and 29 has the recent time.
$dt1=$_GET['dt'];
$query="SELECT * FROM table ORDER BY dt DESC";
$result1 = mysql_query($query);
$table = mysql_fetch_array($result1, MYSQL_ASSOC);
$dt2=$table['dt'];
echo $dt2."
"; // if here i echo $table['id']; the result is here 29
if(strtotime($dt1) < strtotime($dt2))
{
while ($table = mysql_fetch_array($result1, MYSQL_ASSOC)){
echo $table['id']."<br />";
echo $table['name']."<br />";
}
}
else
echo "false";
Why the last id is not shown i.e 29
You read your first line into
$tableon line 3So when entering your while loop you read the second row into
$tablecausing you to miss the first row.EDIT :
You can prevent this by resetting the rowpointer right before you start your while loop like this: