0

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

4
  • The line that's throwing the error seems to be the one where you reference $row['url']. Can you confirm that you have a url column in your uploaded_images table? Commented Mar 10, 2012 at 19:45
  • Yeah, that was of course the error. Thanks a bunch. Been coding almost 8 hours straight. Maybe time to stop now and make some food. Commented Mar 10, 2012 at 19:51
  • Probably a good idea :^) Commented Mar 10, 2012 at 19:52
  • Copy your comment as an answer and I'll make it the solution and vote it up. :) Commented Mar 10, 2012 at 19:54

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

Something is missing from your return.

1 Comment

No actually I tried that and it didn't work, the problem was that I didn't have an url column in my table.:)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.