如何获得计数结果?

我有这个代码。直接运行它应该返回100。但是有了这个代码,它返回1。我是否使用 ?错了,或者为什么它只返回1?



 <?php


require '../notWebsite/dbh.php';

session_start();

$userID = (int)$_SESSION['userID'];


$sqlCount = "SELECT COUNT(groupID) FROM savedbyuser WHERE userID = ?";

$stmt = mysqli_stmt_init($conn);


if(!mysqli_stmt_prepare($stmt, $sqlCount)) {

header("Location: ../GymnasieArbeteHemsida.php?error=countError");

 exit();

}

else {

mysqli_stmt_bind_param($stmt, "i", $userID);

mysqli_stmt_execute($stmt);


$count = mysqli_stmt_execute($stmt);

echo $count;

     exit();

}


mysqli_stmt_close($stmt);

mysqli_close($conn);




?>


慕无忌1623718
浏览 74回答 1
1回答

白衣非少年

如手册&nbsp;https://www.php.net/manual/en/mysqli-stmt.execute.php&nbsp;所述Returns&nbsp;TRUE&nbsp;on&nbsp;success&nbsp;or&nbsp;FALSE&nbsp;on&nbsp;failure.所以这个$count&nbsp;=&nbsp;mysqli_stmt_execute($stmt); echo&nbsp;$count;转换为$count&nbsp;=&nbsp;true; echo&nbsp;$count; //&nbsp;print&nbsp;1在手动聚焦上Note: When&nbsp;using&nbsp;mysqli_stmt_execute(),&nbsp;the&nbsp;mysqli_stmt_fetch()&nbsp;function&nbsp;must&nbsp;be&nbsp;used&nbsp;to&nbsp;fetch&nbsp;the&nbsp;data&nbsp;prior&nbsp;to&nbsp;performing&nbsp;any&nbsp;additional&nbsp;queries.导致&nbsp;https://www.php.net/manual/en/mysqli-stmt.fetch.php&nbsp;等等...
打开App,查看更多内容
随时随地看视频慕课网APP