gpt4 book ai didi

PHP Warning : mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, string in given in ..... with SELECT MAX

转载 作者:行者123 更新时间:2023-12-01 00:39:51 28 4
gpt4 key购买 nike

我知道论坛上有数百万这样的帖子,但似乎没有一个对我的问题有帮助。这是 PHP 代码:

  $countsql = "SELECT MAX(id) as count FROM art";
$count = mysqli_query($link, $countsql);
if(!$count){
echo "Error\n";
echo "Code: ". mysqli_error($link);
exit;
}

while ($row = mysqli_fetch_assoc($count)){ $count = $row["count"]; }

$ppp = 2;
$start = $count - (($page-1) * $ppp);
$end = $count - (($page-1) * 2 * $ppp);

问题出现在与 mysqli_fetch_assoc 相关的行中。任何帮助将不胜感激。

最佳答案

你的问题在这里:

while ($row = mysqli_fetch_assoc($count)){ 
$count = $row["count"];
}

第二次迭代将 $count 设置为字符串,使 mysqli_fetch_assoc 调用失败。

因为结果集中只有一行,所以可以将 while 更改为 if:

if ($row = mysqli_fetch_assoc($count)){ 
$count = $row["count"];
}

或者,更好的是,不要将同一个变量用于两个(截然不同的)目的。

$count_result = mysqli_query($link, $countsql);
...
if ($row = mysqli_fetch_assoc($count_result)){
$count = $row["count"];
}

关于PHP Warning : mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, string in given in ..... with SELECT MAX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35582820/

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