我有一个名为Book的表,它有一个字段(BorrowTime),一旦被借走,它就会递增。类似于下面的内容
我想检索借阅时间最长的前10条记录。我的sql语句:
$results = mysql_query("SELECT * from books order by BorrowTime DESC LIMIT 10");
while ($row = mysql_fetch_array($results))
{
echo $row['Title'];
}它不工作并且有无限循环。有人知道哪里出问题了吗?
发布于 2011-04-25 21:17:16
您的代码没有问题,但请尝试使用此脚本进行调试。
$results = mysql_query("SELECT * from books order by BorrowTime DESC LIMIT 10");
while ($row = mysql_fetch_assoc($results))
{
print_r($row);
exit;//force exit script to debuging, are we get correct result or not
}发布于 2011-04-26 03:27:33
将您的代码更改为:
$results = mysql_query("SELECT Title from books order by BorrowTime DESC LIMIT 10");
while ($row = mysql_fetch_array($results)){
echo $row['Title'];
}因为您只使用了字段'Title',而没有该表中的其他字段。
同样,当这个字段被定义为'title‘时,$row'Title’不会显示任何内容,因为你应该使用$row'title‘。
https://stackoverflow.com/questions/5776135
复制相似问题