Note that there are some explanatory texts on larger screens.

plurals
  1. POGet only personal record of the DB and not all of the records
    primarykey
    data
    text
    <p>When you log in on my site, you'll directly be directed to your profiles page. So that you can see your name, phone, email, etc. But at the moment when I log in on my site, I get directed to my profile page but I get all data for every user in my DB. So I'm getting the name of every user, the phone of every user, etc. I only want to get the data of the person who logged in. How can I achieve this? I did some thinking about it, and came up with doing a <code>where userID = ID of the user HERE</code> But I don't know where I'll be able to get the ID of this user. When logging in I'm starting a session, so would I need to store the logged in users ID in the session? Or isn't that secure?</p> <p>I'm learning and working with CodeIgniter, so I'm doing it in a MVC pattern.</p> <p><strong>Controller where I login and set my session</strong></p> <pre><code>if($query){ $data = array( 'username' =&gt; $this-&gt;input-&gt;post('loginEmail'), 'is_logged_in' =&gt; true ); $this-&gt;session-&gt;set_userdata($data); </code></pre> <p><strong>Controller</strong></p> <pre><code>if($logged_in){ //if the user is logged in $this-&gt;load-&gt;model('profile_model'); if($query = $this-&gt;profile_model-&gt;userInfo()){ $data['records'] = $query; $data['content'] = 'profile_view'; $this-&gt;load-&gt;view('templates/template', $data); } } </code></pre> <p><strong>Model</strong> <pre><code>class Profile_model extends CI_Model{ function userInfo(){ $query = $this-&gt;db-&gt;get('tbl_users'); return $query-&gt;result(); } } </code></pre> <p><strong>View where my I want to show my data</strong></p> <pre><code>if(isset($records)){ foreach($records as $row){ echo $row-&gt;username; echo $row-&gt;cellphone; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload