Forgive me if this was answered. I saw various answers to json data and openlibrary
So far, the json data that I get from openlibrary and the json data that I see in the examples look in the format
My question is: use php (or javascript), how can I get the data in an array or indavidual variables and put them in the mysql database.
- addition to the previous question - I would like to display the raw data below:
Title: Book Tile Author: Isbn Book Author: Isbn Number, etc.
and then put this data in mysql database
[Update 2015-011-07] Now I got a response, I updated the code below to show how it should be. The following will request json data from openlibrary and it will be returned as a string. The ISBN number in $ url is for testing purposes only, so be sure to replace it.
<?php $url ="https://openlibrary.org/api/books?bibkeys=ISBN:0789721813&jscmd=details&format=json"; $headers = array( "Content-type: application/json;charset=\"utf-8\"", "Accept: text/xml", "Cache-Control: no-cache", "Pragma: no-cache", "SOAPAction: \"run\"" ); $cURL = curl_init(); curl_setopt($cURL, CURLOPT_URL, $url); curl_setopt($cURL, CURLOPT_HTTPGET, true); curl_setopt($cURL, CURLOPT_HTTPHEADER, $headers); curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($cURL); foreach (json_decode($result, true) as $book) { printf("\nISBN: %s\ttitle: %s\tauthor: %s", $book['details']['isbn_10'][0], $book['details']['title'], $book['details']['contributions'][0]); } curl_close($cURL); ?>
When the page loads, the following is displayed:
ISBN: 0789721813 title: Red Hat Linux author: Hellums, Duane