简体   繁体   中英

Login in Codeigniter display the current user details after successful login

controller:

 public function view()
        {
        $seid=$this->session->userdata('user_id');
        $data['result']=$this->search_model->getall($seid);
        $this->load->view('pagination_view',$data);
        }

model:

public function getall($seid)
{
    $this->db->select('uid','name','details','img');
    $this->db->where("email",$seid);
     $q=$this->db->get('tbl_reg');
    return $q->result();
}

view:

<?php foreach($result as $row){?>
<?php <?php   echo "username:".$row['name'];die();?> 

<br/>
<?php echo "email:" .$row['email'];?>
<br/>
<?php echo "user id:" .$row['uid'];?>
<?php echo "Details:".$row['details'];?>
<img src="<?php echo $row['img'] ;}?>"  style="width:104px;height:142px"; />

when i logged in to the home page , did not display the current logged in user details. what is the problem with this code .Please provide solution for this problem?

If you want to get single row from database please use $q->row_object() or $q->row_array() . Then you don't need to use foreach on view. Please see below example:-

Your Modal

public function getall($seid)
{
    $this->db->select('uid','name','details','img');
    $this->db->where("email",$seid);
    $q=$this->db->get('tbl_reg');
    return $q->row_array();
}

On your View

<?php   echo "username:".$row['name']; ?> 
<br/>
<?php echo "email:" .$row['email'];?>
<br/>
<?php echo "user id:" .$row['uid'];?>
<?php echo "Details:".$row['details'];?>
<img src="<?php echo $row['img'] ;?>"  style="width:104px;height:142px"; />

modify your model to use the following:

public function getall($seid)
{
    $this->db->select('uid','name','details','img');
    $this->db->where("email",$seid);
    $q=$this->db->get('tbl_reg');

    return $q->result_array();
}

In controller, add the user details in the following manner,

public function view()
    {
    $seid=$this->session->userdata('user_id');
    $data['result']=$this->search_model->getall($seid);
    $newdata = array(
               'username'  => <USERNAME>,
               'email'     => <MAILID>,
                ...........
               'logged_in' => TRUE
           );

    $this->session->set_userdata($newdata);
    $this->load->view('pagination_view',$data);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM