gpt4 book ai didi

php - 将 MYSQL 查询限制为 1 个结果 fetch_assoc() 停止失败

转载 作者:行者123 更新时间:2023-11-29 12:26:35 25 4
gpt4 key购买 nike

如何将数据库查询限制为只有 1 个结果,以便 fetch_assoc() 不会失败。限制 1 似乎不起作用,我收到错误,并且 php 函数与下面的 sql 一起使用。

警告:mysqli::query(): (21000/1242):子查询在/class.php 第 463 行返回超过 1 行

fatal error :在第 465 行/class.php 中的非对象上调用成员函数 fetch_assoc()

public function getLastTimeStampStatusChanged($column) {

$sql = "select max(`timeStamp`) from `status` where `".$column."` !=(select `".$column."` from `status` where `timeStamp` = (select max(`timeStamp`) from `status` LIMIT 1))";

while (!$query) {

$query = $this->db->query($sql);

while ($row = $query->fetch_assoc()) {

$result[] = $row;

}

}

return $result;


}

最佳答案

简短的回答是,您需要在 SELECT 列表中没有聚合的查询上使用 LIMIT 子句。最小的修复方法是移动右括号...

更改此:

... from `status` LIMIT 1))
^

对此:

... from `status`) LIMIT 1)
^
<小时/>

更长的答案是这可能不会返回您想要的结果,因为它只会返回一些行,而不是任何确定的行。

关于php - 将 MYSQL 查询限制为 1 个结果 fetch_assoc() 停止失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28220405/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com