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.

24
  • There is a return statement before the print_r function. Also, the { at the end of the else statement is not needed (and should be causing an error). Commented Aug 7, 2015 at 3:11
  • when i see the page source on my browser "<img title="profile image" class="img-circle img-responsive" src=" ">" is displayed Commented Aug 7, 2015 at 3:25
  • try replacing your view as <img title="profile image" class="img-circle img-responsive" src="<?php echo base_url('Controller/function').$img; ?>"> Commented Aug 7, 2015 at 3:44
  • what is in profile_picture in table?? Commented Aug 7, 2015 at 3:47
  • 1
    @Optimmus can you print $data and $query->num_rows() and check output Commented Aug 7, 2015 at 4:08

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

i am getting undefined variable $data in model and $img in controller
Have you solved you above issue? of undefined $data and $img ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.