Rectangle 27 0

php get user data from its session Codeigniter?


$data['result'] = $this->model_name->getdata($id);
function getdata($id){
    $query = "select peng.*, masha.* 
    from pengguna peng join mashasiswa masha 
    on id_pengguna where masha.id_pengguna = $id";
    $query = $this->db->query($query);
    return $query->result_array();
}

You can run this query in model and will get the data from both the tables and then can use it. send id to the model of the id_pengguna. This id will be the user id for comparison Model

first you will get the id from the table where you actually login in. then pass that id to the model.

id_pengguna this is the id you need to get. and then pass through the controller. You got it.

Note
Rectangle 27 0

php get user data from its session Codeigniter?


$data["row"] = $this->Mprofile->getmahasiswa();
$this->db->where('id_pengguna', $idpengguna);
$this->db->where('idpengguna', $idpengguna);
<?php
   if ($row){
       $nim= $row->nim;
       $nama_mahasiswa = $row->nama_mahasiswa;
       $email = $row->email;
       $telepon= $row->telepon;
   } else {
       $nim =
       $nama_mahasiswa =
       $email = 
       $telepon = "";
   }
?>
<?php echo $row->nim;?>
<?php echo $row['nim'];?>
<ul class="category-t">
   <li><?php echo $nim;?></li>
   <li><?php echo $nama_mahasiswa;?></li>
   <li><?php echo $email;?></li>
   <li><?php echo $telepon;?></li>
</ul>
function getmahasiswa(){
   $idpengguna = $this->session->userdata('idpengguna');

   $this->db->where('id_pengguna', $idpengguna);
   $q = $this->db->get('mahasiswa');
   return $q->row();
}

@MirzaChilman do you test it when not logged in?

Add this at the top of your view

And in your view

Its simple, you can create a new query selecting data from your mahasiswa table.

still i've got the same issue

yes i did and still the same issue, and when i called it with another way like using $row['nim'];, there's no result at all, how to change it into an object?

Note