douken7402 2015-01-04 14:28
浏览 86
已采纳

Mysqli在查询中是否支持MAX?

I want to get the last date from a table. So I can show the last added or changed item:

$qry = " 
        Select
            MAX(changedate)
        FROM
            producten   
        ";
    $stmt = $connection->prepare($qry);             
    $stmt->error;
    $stmt->execute();
    $result = $stmt->get_result();
    $up = $result->fetch_assoc();
    $stmt->close();

$main .='Last update '.$up['changedate'];

But I receive this error message:

Notice: Undefined index: changedate in /home/jcslnl/domains/jcsl.nl/public_html/michael/paginas/home.php on line 22

Is this because MAX is not longer supported? Or should I continue to search for the error?

It could also be that I did something wrong in the table, it's the firsttime i used timestamp i.s.o. unix timestamp.

  • 写回答

6条回答 默认 最新

  • dsxxqndv41105 2015-01-04 14:34
    关注

    The answer to your question is yes, mysqli supports MAX. However, you need to alias the column, since you aren't actually selecting the column changedate, but the result of a function which selects the value of changedate. In which case SELECT MAX(changedate) as changedate provides you with the desired result.

    You can also use var_dump($up); to see this more clearly in your result.

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

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理