Using PHP and MySQL I would like to retrieve a list of book covers based on their ISBN which I have in my database.
According to this answer, I can use the following URL;
https://www.googleapis.com/books/v1/volumes?q=isbn:0751538310
This works fine, and returns a JSON response. However I want to do this for 10 books, not just one - how do I achieve this?
My code so far;
Model
public function itemList() {
$query = $this->db->get('item', 10);
return $query->result_array();
}
A var_dump($this->items_model->itemList())
returns https://pastebin.com/nY5bFMmw
Controller
$page = file_get_contents("https://www.googleapis.com/books/v1/volumes?q=isbn:0751538310");
// I need to replace the above ISBN with the 10 from my database
$data = json_decode($page, true);
echo "Image = " . '<img src="'.$data['items'][0]['volumeInfo']['imageLinks']['thumbnail'].'" alt="Cover">';
// This successfully prints 1 image. I need 10.
View
// What do I need to do in order to print 10 different images
<table>
<tr>
<td><strong>Image</strong></td>
</tr>
<tr>
<td>// image here x 10</td>
</tr>
</table>
I think I need a foreach
loop somewhere but I'm not really sure how or where?