Liam Ure Liam Ure - 1 year ago 51
JSON Question

Im trying to encode all data from a table in JSON but there is no result

Here is the webpage in question

Here is the database

And here is the SQL code

$con=mysqli_connect('host', 'user', 'Password', 'database');
echo "Failed Connection" . mysqli_connect_errno();
$sth = mysqli_query("SELECT * FROM quotes");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
$rows[] = $r;
print json_encode($rows);



When the webpage is run all that gets returned is "[]" (You can see this by clicking the URL above)

Answer Source

The first argument of mysqli_query function is the connection link object:

$sth = mysqli_query($con, "SELECT * FROM quotes");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download