2012-03-10 19:35
浏览 48


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:

class imageLoader extends CI_Model {

    var $gallery_path;
    var $gallery_path_url;

    function __construct() {
        $this->gallery_path = realpath(APPPATH . '../public_html/images');
        $this->gallery_path_url = base_url() . 'images/';

    function get_images() {
            $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:

    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>
            <?php $x++;
            /*if($x == 21)
        endforeach; else: ?>

My old code that sucks but work:

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongpenggan6812 2012-03-10 19:59

    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.

    解决 无用
    打赏 举报
  • douyinzha5820 2012-03-10 19:51

    Something is missing from your return.

    解决 无用
    打赏 举报

相关推荐 更多相似问题