pretty much like the getJSON example I showed before:
Call an empty array before the while loop
Then populate the array in the loop
Then encode the array when your out of the loop.
Here is another example using an sqlite database that can be used with the HTML example above:
<?php
error_reporting(-1);
$db = new PDO('sqlite::memory:');
$db->exec('CREATE TABLE test(id INTEGER PRIMARY KEY, title VARCHAR NOT NULL UNIQUE)');
$db->exec('INSERT INTO test VALUES(1, "Title 1")');
$db->exec('INSERT INTO test VALUES(2, "Title 2")');
$db->exec('INSERT INTO test VALUES(3, "Title 3")');
$arr = array();
foreach( $db->query('SELECT * FROM test', PDO::FETCH_ASSOC) as $row ) {
$arr[] = $row;
}
echo json_encode($arr);
?>
Hi, thank you for your response. I have it working now.
Last question, I noticed all the html for the output is in the javascript. Is there a way to put it outside the javascript?