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

如何从表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.

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)