使用codeigniter在导航栏中显示配置文件图像

I am trying to show user image in navbar top section like Username "Image" just like in this site or any other.

This is what i try.

View

 <li class="">
                    <a href="#" class="user-profile dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                        <img src="<?php echo base_url(); ?>profileimages/<?php if (isset($_SESSION['Prof']))
                        {
                            echo $_SESSION['Prof'];
                        }?>" alt=""><?php echo $admin;?>
                        <span class=" fa fa-angle-down"></span>
                    </a>
                    <ul class="dropdown-menu dropdown-usermenu pull-right">
                        <li><a href="Profile"> Profile</a></li>
                        <li><a href="Profile_Setting"> Setting</a></li>
                        <li><a href="logout"><i class="fa fa-sign-out pull-right"></i> Log Out</a></li>
                    </ul>
                </li>

I am putting the image in session in login model,

Model

public function login_admin($username,$password)
    {
        $query=$this->db->where(['Username'=>$username,'Password'=>$password])->get('dc_admin');
        if($query->num_rows()>0)
        {
            foreach ($query->result() as $row)
            {
                $q=$row->Profile_Picture;
                $_SESSION['Prof']=$q;
            }

            $this->session->set_userdata('logged_in',$username);
            redirect('Master/Users');
        }
        else
        {
            redirect('Master');
        }

    }

I am new in CI and try to learn, please tell what i can do here to get image, i am able to get the logged IN username but not the image.

Any help will be appreciated.

I just make a simple change in my code, and follow the session idea by the above Answers. The below code fixed my issue.

 public function login_admin($username,$password)
{
    $query=$this->db->where(['Username'=>$username,'Password'=>$password])->get('dc_admin');
    //this is for single record

    if($query->num_rows()>0)
    {
        $rw = $query->row();
        $q = $rw->Profile_Image;
        $this->session->set_userdata('prfimg', $q);
        $this->session->set_userdata('logged_in',$username);
        redirect('Master/Users');
    }
    else
    {
        redirect('Master');
    }

}

MODEL

Step One

Get the result from your query

function getUserDetails($user_id){
 $this->db->where('user_id', $user_id);
 $query = $this->db->get('tbl_user');

 return $query->row();
}

Step Two

As @cssBlaster21895 said, insert the profile picture inside your session

$user_details = $this->M_Model->getUserDetails($user_id);
if($user_details){
 $this->session->set_userdata('profile_picture', $user_details->profile);
}

// Load your view

Note This has to be within the controller

Step Three

Add the image to your navbar

<img src = "<?php if($this->session->userdata('profile_picture')) { echo $this->session->userdata(''profile_picture); } ?>" />

Note Something to note is, you would set the session when the user logs in then add the image to your navbar in your template.

Hope this helps