dongzhilian0188
2012-03-10 19:35
浏览 48
已采纳

CodeIgniter中多维数组的未定义索引

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

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

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.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题