I am trying to count total number of rows with the following code:
$countvideo = "SELECT count(id) FROM `videos`";
$countvideo_run = mysqli_query($connect, $countvideo);
if($countvideo_run){
$countvideo_result = mysql_result($countvideo_run, 0, 'count(id)');
}
but it shows me this error:
Warning: mysql_result() expects parameter 1 to be resource, object given in C:\xampp\htdocs\task\media ew\adminpanel.php on line 121
how can I count this?
You are mixing mysqli
and mysql
functions
$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;
}
You used mysql_result
instead of mysqli_result
.
You are mixing a mysqli_
return object with an incompatible mysql_
function.
$countvideo = "SELECT count(id) qty FROM `videos`";
if (($result = mysqli_query($connect, $countvideo)) !== false) {
$row = $result->fetch_assoc();
$countvideo_result = $row['qty'];
}