【问题标题】:Notice: Object of class mysqli_result could not be converted to int注意:类 mysqli_result 的对象无法转换为 int
【发布时间】:2017-09-08 18:47:12
【问题描述】:

我已经搜索了几乎与我的案例相同的所有问题。但我仍然很困惑。我刚刚学习了 php 编程并遇到了这样的问题: 注意:mysqli_result 类的对象无法转换为 int ... 请帮我解决上述问题。

    <?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;
?>

【问题讨论】:

标签: php mysqli


【解决方案1】:

1.$dmysqli_result 对象。首先从中获取数据,然后使用它。

2.不要将mysql_*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
  }
?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-05
    相关资源
    最近更新 更多