Liam Ure Liam Ure - 17 days ago 8
JSON Question

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

Here is the webpage in question

http://liamure.xyz/rsk/getdata.php

Here is the database
Database

And here is the SQL code

<?php
$con=mysqli_connect('host', 'user', 'Password', 'database');
if(mysqli_connect_errno())
{
echo "Failed Connection" . mysqli_connect_errno();
}
else
{
$sth = mysqli_query("SELECT * FROM quotes");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
echo"1";
$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

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

$sth = mysqli_query($con, "SELECT * FROM quotes");