Reputation: 4712
This will probably be very easy to get a solution for, but I can't get it to work and I've been trying some different methods I've found online ( read SO ). The strange is that my code worked perfectly when I had a different source for the images.
Anyway my error:
Message: Undefined index: url
Filename: models/imageloader.php
Line Number: 21
The code creating the array:
<?php
class imageLoader extends CI_Model {
var $gallery_path;
var $gallery_path_url;
function __construct() {
parent::__construct();
$this->gallery_path = realpath(APPPATH . '../public_html/images');
$this->gallery_path_url = base_url() . 'images/';
}
function get_images() {
//$this->session->userdata('email')
$this->db->where('upload_email', $this->session->userdata('email'));
$query = $this->db->get('uploaded_images');
$images = array();
if($query->num_rows > 0) {
foreach($query->result_array() as $row) {
$images[] = array(
'url' => $this->gallery_path_url . $row['url'],
'thumb_url' => $this->gallery_path_url . 'thumbs/' . $row['url']
);
}
return $images;
}
}
}
And last the view for displaying some images:
<?php
$x=0;
if(isset($images) && count($images)):
foreach($images as $image): ?>
<div class="thumb">
<a href="<?php echo $image['url']; ?>"><img src="<?php echo $image['thumb_url']; ?>" /></a>
</div>
<?php $x++;
/*if($x == 21)
break;*/
endforeach; else: ?>
My old code that sucks but work: http://pastie.org/3566053
Upvotes: 0
Views: 668
Reputation: 16510
The line that's throwing the error seems to be the one where you reference $row['url']. If you don't already have a url
column in your uploaded_images
table, adding one ought to fix your problem.
Upvotes: 2