我知道在论坛上有数百个这样的帖子,但似乎没有一个可以帮助我解决问题.这是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);
Run Code Online (Sandbox Code Playgroud)
问题出现在mysqli_fetch_assoc的行中.任何帮助都将很高兴.
你的问题在这里:
while ($row = mysqli_fetch_assoc($count)){
$count = $row["count"];
}
Run Code Online (Sandbox Code Playgroud)
第二次迭代设置$count为字符串,使mysqli_fetch_assoc调用失败.
因为结果集中只有一行,所以可以更改while为if:
if ($row = mysqli_fetch_assoc($count)){
$count = $row["count"];
}
Run Code Online (Sandbox Code Playgroud)
或者,更好的是,不要将相同的变量用于两个(非常不同的)目的.
$count_result = mysqli_query($link, $countsql);
...
if ($row = mysqli_fetch_assoc($count_result)){
$count = $row["count"];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1172 次 |
| 最近记录: |