Reputation: 13
I've searched all the questions that are almost identical to my case. but I am still confused .I just learned php programming and got an problem like this: Notice: Object of class mysqli_result could not be converted to int in ... please help me to solve the above problem.
<?php
$per_hal=10;
$jumlah_record="SELECT COUNT(*) from user";
$d=mysqli_query($link, $jumlah_record);
if($d == FALSE) { die(mysql_error()); }
$halaman=ceil($d / $per_hal); //error here
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_hal;
?>
Upvotes: 1
Views: 2318
Reputation: 72299
1.$d
is the mysqli_result
object. first get data from it and then use it.
2.don't mix mysql_*
with mysqli_*
.
<?php
$per_hal=10;
$jumlah_record="SELECT COUNT(*) as total_count from user";
$d=mysqli_query($link, $jumlah_record);
if($d) {
$result = mysqli_fetch_assoc($d); //fetch record
$halaman=ceil($result['total_count'] / $per_hal); //error here
$page = (isset($_GET['page'])) ? (int)$_GET['page'] : 1;
$start = ($page - 1) * $per_hal;
}else{
die(mysqli_error($link)); // you used mysql_error() which is incorrect
}
?>
Upvotes: 1