user5182392
user5182392

Reputation:

image not displayed?

I am trying to display an image from database.There were no errorin code Could anybody help me to sort it out?

   //Model

 function getImage()
    {
        $id = $this->session->userdata('user_id');
        $this->db->where('user_id',$id);
        $r=$this->db->get('tbl_usrs');
        if($r->num_rows()>0)
        {
            foreach ($r -> result_array() as $row) {
            $data[] = $row;
            }
        }
        $r->free_result();
        return $data; //error
    }


 Controller
public function index() {
        if($this->session->userdata('is_login')) {

        $session_data = $this->session->userdata('sessiondata');
        $id = $session_data['user_id'];
        $this->load->model('Display_profilepicture');
        $data = $this->Display_profilepicture->getImage();
        //print_r($data);
        $img = base_url().$data;
        $data=array('profile_picture'=>$img);
        //$this->load->view('header');
        $this->load->view('my_profile',array('data'=>$data));
            }

view
      <div class="col-sm-2"><a href="<?php echo base_url('Profile_pic/index') ?>" class="pull-right"><img title="profile image" class="img-circle img-responsive" src="<?php echo isset( $img) ?>"></a>

this is result of my var_dump result array(1) { ["profile_picture"]=> string(70) "http://localhost/ko//upload/large/c4bd859f588751f33c0dfd0907bbff24.jpg" }

Upvotes: 1

Views: 57

Answers (2)

Al Amin Chayan
Al Amin Chayan

Reputation: 2500

//Model

    function getImage()
    {
        $id = $this->session->userdata('user_id');
        $this->db->where('user_id',$id);
        $r=$this->db->get('tbl_usrs');
        $data = array();
        if($r->num_rows()>0)
        {
            foreach ($r -> result_array() as $row) {
            $data[] = $row;
            }
        }
        $r->free_result();
        return $data;
    }


 Controller
public function index() {
        if($this->session->userdata('is_login')) {

        $session_data = $this->session->userdata('sessiondata');
        $id = $session_data['user_id'];
        $this->load->model('Display_profilepicture');
        $data = $this->Display_profilepicture->getImage();
        //print_r($data);
        $img = base_url().$data['profile_picture'];
        $data=array('profile_picture'=>$img);
        //$this->load->view('header');
        $this->load->view('my_profile',$data);
            }

view
      <div class="col-sm-2"><a href="<?php echo base_url('Profile_pic/index') ?>" class="pull-right"><img title="profile image" class="img-circle img-responsive" src="<?php echo $profile_picture; ?>"></a>

Upvotes: 0

RhapX
RhapX

Reputation: 1683

It appears that you are calling a variable named $img yet you are not setting it anywhere above the reference.

$data=array('profile_picture'=>$img);

Further, you are calling a variable which again is undefined in the view.

And finally you are not echoing the variable:

src="<?php echo $img ?>"

Try setting the variable $img to something and this will resolve your issue.

Here are a couple of references to learning variables and understanding how they work.

Upvotes: 2

Related Questions