problem in query order by decending
$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 n开发者_开发技巧ot shown i.e 29You read your first line into $table
on line 3
$result1 = mysql_query($query);
So when entering your while loop you read the second row into $table
causing you to miss the first row.
EDIT : You can prevent this by resetting the rowpointer right before you start your while loop like this:
mysql_data_seek($query,0);
while(..........
you're doing fetch array out of while loop so in while loop you get -1 records from fetch_array.
As I am guessing you're doing the filter by date with GET['dt'] variable.
you can filter records directly in SQL query.
Like this
SELECT * FROM table WHERE dt > {$_GET['dt']} ORDER BY dt DESC
beware to pass the correct format of the date.
Just delete your line $table = mysql_fetch_array($result1, MYSQL_ASSOC);
and it will work :
$dt1=$_GET['dt'];
$query="SELECT * FROM table ORDER BY dt DESC";
$result1 = mysql_query($query);
$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";
精彩评论