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

?>

avatar joe007
@joe007

17 Kontribusi 1 Poin

Diperbarui 4 tahun yang lalu

2 Jawaban:

<div>hai @joe007 karena data yang kamu tampilkan sebelumnya itu array bukan object, coba kamu ubah dibagian while-nya jadi mysqli_fetch_array()</div>

avatar bosque
@bosque

187 Kontribusi 104 Poin

Dipost 4 tahun yang lalu

Tanggapan

ok saya cobanya..thx yaa

<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 :&nbsp;<br>Sebelum :</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 &#039;../config/connection.php&#039;;
     
$sql=&quot;select count(*) from user&quot;;
$rs = mysqli_query($db,$sql);
$row = mysqli_fetch_row($rs);

$result[&quot;total&quot;] = $row[0];
$rs = mysql_query(&quot;select * from user limit $offset,$rows&quot;);

$items = array();

while($row = mysqli_fetch_object($db,$rs)){
	array_push($items, $row);
}
$result[&quot;rows&quot;] = $items;

echo json_encode($result);&lt;/pre&gt;&lt;/pre&gt;&lt;div&gt;&lt;br&gt;Sesudah :&lt;br&gt;&lt;br&gt;&lt;/div&gt;&lt;pre&gt;&lt;br&gt;&lt;pre&gt;&amp;lt;?php
$page = isset($_POST[&#039;page&#039;]) ? intval($_POST[&#039;page&#039;]) : 1;
$rows = isset($_POST[&#039;rows&#039;]) ? intval($_POST[&#039;rows&#039;]) : 10;
$offset = ($page-1)*$rows;
$result = array();

include &#039;../config/connection.php&#039;;
     
$sql=&quot;select count(*) from user&quot;;
$rs = mysqli_query($db,$sql);
$row = mysqli_fetch_row($rs);

$result[&quot;total&quot;] = $row[0];
$rs = mysqli_query($db, &quot;select * from user limit $offset,$rows&quot;);

$items = array();

while($row = mysqli_fetch_object($rs)){
	array_push($items, $row);
}
$result[&quot;rows&quot;] = $items;

echo json_encode($result);

<br></pre><br><br></pre>

avatar ahanafi
@ahanafi

815 Kontribusi 554 Poin

Dipost 4 tahun yang lalu

Login untuk ikut Jawaban