I'm testing the JSON feature in Postgres for NOSQL.
I have PostgreSQL "testdb"
And table "multimedia"
INSERT INTO multimedia (data) VALUES ('{"id":"1", "title":"Iliade", "type":"ebook", "pages":"250"}');
INSERT INTO multimedia (data) VALUES ('{"id":"2", "title":"Pavarotti", "type":"CD", "tracks":"9"}');
INSERT INTO multimedia (data) VALUES ('{"id":"3", "title":"art", "type":"photo", "pixels":"100x100"}');
Now I would like to extract data with PHP
$conn = pg_connect("host=localhost port=5432 dbname=testdb user=postgres password=xxx");
if(!$conn) {
die("Error sorry !");
} else {
echo "OK";
}
if(!$query = @pg_query("SELECT * FROM multimedia;"))
die("Error in query:" . pg_last_error($conn));
$myarray = array();
while ($row = pg_fetch_row($query)) {
$myarray[] = $row;
}
echo json_encode($myarray);
This will print all the data, But I do not understand how to extract only the value of all field "id" and "title" in to html table ...