Liam Ure Liam Ure - 4 months ago 23
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");