Postingan lainnya
Warning: mysqli_fetch_object() expects parameter 1 to be mysqli_result, object given
Hai,
Pesan error Warning: mysqli_fetch_object() expects parameter 1 to be mysqli_result, object given
penyebabnya apa ya?
Error terdapat pada perintah :
while($row = mysqli_fetch_object($db,$rs))
code keseluruhannya :
<?php
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset = ($page-1)*$rows;
$result = array();
include '../config/connection.php';
$sql="select count(*) from user";
$rs = mysqli_query($db,$sql);
$row = mysqli_fetch_row($rs);
$result["total"] = $row[0];
$rs = mysql_query("select * from user limit $offset,$rows");
$items = array();
while($row = mysqli_fetch_object($db,$rs)){
array_push($items, $row);
}
$result["rows"] = $items;
echo json_encode($result);
?>
0
2 Jawaban:
<div>Hallo seperti nya agan salah penulisan sintaks, dari kode yg di lampirkan itu ada yg pake mysql, ada juga yg pake mysqli,<br><br>Coba ubah kaya gini : <br>Sebelum :</div><pre><br><pre><?php $page = isset($_POST['page']) ? intval($_POST['page']) : 1; $rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10; $offset = ($page-1)*$rows; $result = array();
include '../config/connection.php';
$sql="select count(*) from user";
$rs = mysqli_query($db,$sql);
$row = mysqli_fetch_row($rs);
$result["total"] = $row[0];
$rs = mysql_query("select * from user limit $offset,$rows");
$items = array();
while($row = mysqli_fetch_object($db,$rs)){
array_push($items, $row);
}
$result["rows"] = $items;
echo json_encode($result);</pre></pre><div><br>Sesudah :<br><br></div><pre><br><pre>&lt;?php
$page = isset($_POST['page']) ? intval($_POST['page']) : 1;
$rows = isset($_POST['rows']) ? intval($_POST['rows']) : 10;
$offset = ($page-1)*$rows;
$result = array();
include '../config/connection.php';
$sql="select count(*) from user";
$rs = mysqli_query($db,$sql);
$row = mysqli_fetch_row($rs);
$result["total"] = $row[0];
$rs = mysqli_query($db, "select * from user limit $offset,$rows");
$items = array();
while($row = mysqli_fetch_object($rs)){
array_push($items, $row);
}
$result["rows"] = $items;
echo json_encode($result);
<br></pre><br><br></pre>
0