1

I have successfully uploaded an image path with an image name in my database. But when it comes to display it doesn't work. I have filed profilepic in my DB.I don't know where I am going, wrong please help to sort.

// Controller

    public function index() {
            if($this->session->userdata('is_login')) {
            $this->load->model('Display_profilepic');
            $data = $this->Display_profilepic->getImage();
            print_r($data);//nothing printed
            $data=array('profile_picture'=>$img);
            $this->load->view("my_profile",$data);



            }

// model Display_profilepic

    function getImage(){
    $id = $this->session->userdata('user_id');
    $this->db->select("*");
    $this->db->from('tbl_usrs');
    $this->db->where('user_id', $id);
    $query = $this->db->get();
    if($query->num_rows()==0)
    echo("Picture not found!");
    else{
    $data = $query->row_array();
    return $data['profile_picture'];
    print_r($data['profile_picture']);//nothing printed

I have a seprate controller and model for inserting the image into the DB where the path is defined. Let me know if I should post that also.

Isaac Bennetch
  • 10,266
  • 2
  • 27
  • 38

1 Answers1

1

Try this code :)

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;
    }

Make sure your $id is not null. So check that once.

David Coder
  • 1,062
  • 2
  • 13
  • 41