I am retrieving data from my MySQL database, and displaying a table including;
item_id
-
item_image
(empty) item_title
-
item_isbn
(contains hyphens)
The code I have so far works, in the sense that I am able to retrieve the data and display it in a simple table.
My code so far;
model
class Items_model extends CI_Model {
public function itemList() {
$query = $this->db->query("SELECT * FROM item LIMIT 10");
return $query->result_array();
}
}
view
<table>
<tr>
<td><strong>ID</strong></td>
<td><strong>Image</strong></td>
<td><strong>Title</strong></td>
<td><strong>ISBN</strong></td>
</tr>
<?php foreach ($items as $item): ?>
<tr>
<td><?php echo $item['item_id']; ?></td>
<td><?php echo $item['item_image']; ?></td>
<td><?php echo $item['item_title']; ?></td>
<td><?php echo $item['item_isbn']; ?></td>
</tr>
<?php endforeach; ?>
</table>
controller
class Items extends CI_Controller {
public function index() {
$data['items'] = $this->items_model->itemList();
$this->load->view('item_view', $data);
}
}
I want to use the book's ISBN, retrieve the book cover using Open Library Covers API and populate the image field in the html table.
Apparently this is possible by using the following URL pattern;
http://covers.openlibrary.org/b/isbn/0385472579-S.jpg
I have tried the following code in my view but it doesn't work;
<td><img src="<?php echo ('http://covers.openlibrary.org/b/isbn/'. stripslashes($item['item_isbn']) .'-S.jpg');?>"/></td>
Ideally I would like to display a standard 'No Image Found' jpg, if I'm unable to retrieve an image using Open Library API also, but I'm sure I can work this part out on my own (hopefully!).
Any advice would be appreciated, very new to Codeigniter.