【发布时间】:2017-03-27 14:47:28
【问题描述】:
使用 PHP 和 MySQL,我想根据我的数据库中的 ISBN 检索书籍封面列表。
根据this answer,我可以使用以下网址;
https://www.googleapis.com/books/v1/volumes?q=isbn:0751538310
这工作正常,并返回 JSON 响应。但是,我想为 10 本书执行此操作,而不仅仅是一本书 - 我该如何实现?
到目前为止我的代码;
型号
public function itemList() {
$query = $this->db->get('item', 10);
return $query->result_array();
}
var_dump($this->items_model->itemList()) 返回https://pastebin.com/nY5bFMmw
控制器
$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.
查看
// 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>
我想我需要一个 foreach 循环,但我不确定如何或在哪里?
【问题讨论】:
标签: php mysql codeigniter oop