I am trying to pull the data from the sample code below (it is through cpanel). I wanted to pull it in JSON encoded format, but there is no data that is displaying. See this screenshot, and my code below it:
Can someone help me with the problem?
<?php
include "db.php";
$data=array();
$q=mysqli_query($con,"SELECT a.*,a.date_added AS date_added2,a.status AS entry_status,a.added_by AS entry_provider FROM entries a WHERE a.status = 'Approved' ORDER BY a.id DESC")
or die(mysql_error());
while ($row=mysqli_fetch_object($q)){
$data[]=$row;
}
echo json_encode($data);
?>
2
Answers
One possibility is that your
$result
is empty.AND
The
mysqli_fetch_object
returns you an object not array.You can use this code to sort out your problem
This can definitely help you.
You use mysqli to get the results, but mysql without i to print error message. These are different extensions, so if there’s an error in your
mysqli_query
call, thenmysql_error
returns empty string and execution stops. Which is what you see in the browser.