我正在尝试使用以下代码计算总行数:
$countvideo = "SELECT count(id) FROM `videos`";
$countvideo_run = mysqli_query($connect, $countvideo);
if($countvideo_run){
$countvideo_result = mysql_result($countvideo_run, 0, 'count(id)');
}
但它显示了我的错误:
警告:mysql_result()要求参数1为资源,对象在第121行的C:\ xampp \ htdocs \ task \ media \ new \ adminpanel.php中给出
我怎么算这个?
答案 0 :(得分:1)
您正在将mysqli_
返回对象与不兼容的mysql_
函数混合。
$countvideo = "SELECT count(id) qty FROM `videos`";
if (($result = mysqli_query($connect, $countvideo)) !== false) {
$row = $result->fetch_assoc();
$countvideo_result = $row['qty'];
}
答案 1 :(得分:0)
您正在混合mysqli
和mysql
个功能
$countvideo = "SELECT count(id) as `total` FROM `users`";
$countvideo_run = mysqli_query($connect, $countvideo);
if ($countvideo_run) {
$countvideo_result = $countvideo_run->fetch_object();
$total = $countvideo_result->total;
}
答案 2 :(得分:0)
您使用mysql_result
代替mysqli_result
。