duanchi19820419
2016-04-25 07:44
浏览 149
已采纳

如何从表mysqli中获取最后一行?

I have a table and am trying to get the most recent row using this code:

include "db_conx.php";

$sql="SELECT column FROM table ORDER BY DESC LIMIT 1";

if ($result=mysqli_query($db_conx,$sql))
  {
  while ($row=mysqli_fetch_row($result))
  {
  printf($row[0]);
  }
  mysqli_free_result($result);
}

It returns a blank result though.

图片转代码服务由CSDN问答提供 功能建议

我有一个表,我正在尝试使用此代码获取最新的行: \ n

 包括“db_conx.php”; 
 
 $ sql =“SELECT列FROM表ORDER BY DESC LIMIT 1”; 
 
if($ result = mysqli_query($ db_conx,$ sql))  
 {
 while($ row = mysqli_fetch_row($ result))
 {
 printf($ row [0]); 
} 
 \ mysqli_free_result($ result); 
} 
    
 
 

但它返回一个空白的结果。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dpnvrt3119 2016-04-25 07:50
    已采纳
    ORDER BY DESC LIMIT 1
    

    ORDER BY what DESC? You have to provide a column name where which you want to order by. Could be an Auto increment column, primary key or even the timestamp etc

    As it currently stands your query has invalid syntax and will not return anything other than an error.

    已采纳该答案
    打赏 评论
  • dongzong5017 2016-04-25 07:51

    you missed column name after order by clause. hope it helps !

    打赏 评论
  • duanluanhui8348 2016-04-25 08:01

    For the ORDER BY you should give a column name of the table. Ex : SELECT * FROM TABLE_NAME ORDER BY table_id DESC LIMIT 1

    In your query you missed the column name to order by.

    打赏 评论

相关推荐 更多相似问题