0
votes

site/views/index.php

<?php foreach($pic as $pic_item): ?> { 
                            <img src="<?php echo base_url('assets1/images/slider/'.$pic_item->pic_item );?>">                   
                    } 
                    <?php endforeach;
                    ?>

controllers/Cspages.php

    public function index()
{


    $this->load->model('gallery_model');

    $pic_unique_id = 18;  // slider

    $data['pic'] = $this->gallery_model->get_picture($pic_unique_id);

    $this->load->view('index', $data);
}

models/Gallery_model.php

public function get_picture($pic_unique_id)
{

    $query = $this->db->get_where('galleries_pictures', array('picture_unique_id' => $pic_unique_id));
    return $query->result();

}

How to fix the following error?

A PHP Error was encountered

Severity: Notice

Message: Undefined property: stdClass::$pic_item

Filename: views/index.php

Line Number: 214

Backtrace:

File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\index.php Line: 214 Function: _error_handler

File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\controllers\Cspages.php Line: 31 Function: view

File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\index.php Line: 315 Function: require_once

http://localhost/masterlinkci2/assets1/images/slider/"> }

1

1 Answers

0
votes

Change your foreach loop in view as below:

<?php foreach($pic as $pic_item): ?>     
<img src="<?php echo base_url('assets1/images/slider/').$pic_item->pic_item;?>">               
<?php endforeach;?>

OR

<?php foreach($pic as $pic_item): ?> 
    <img src="<?php echo base_url('assets1/images/slider/'.$pic_item->pic_item );?>">                   
<?php endforeach;?>

UPDATE

Model

<?php
    public function get_picture($pic_unique_id)
    {

        $this->db->where('picture_unique_id',$pic_unique_id);
        $query = $this->db->get_where('galleries_pictures');
        return $query->row;

    }

Controller

public function index()
{

    $this->load->helper('url');//load url helper
    $this->load->model('gallery_model');

    $pic_unique_id = 18;  // slider

    $data['pic'] = $this->gallery_model->get_picture($pic_unique_id);

    $this->load->view('index', $data);
}

view

<img src="<?php echo base_url('assets1/images/slider/'.$pic->pic_item );?>">