Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to not select an id that is listed in another table from an adjoining table in SQL?
    text
    copied!<p>A little more background on my issue. I have a "Followers" sidebar on my site where users can follow other users. The problem is that currently the users that appear in this sidebar can also include users they already follow. I would like to modify the function so this no longer happens. Here is the model function that I currently use...</p> <pre><code>public function get_oldest($limit = 10, $user_id) { $this-&gt;db -&gt;select($this-&gt;db-&gt;dbprefix('profiles').'.*, g.description as group_name, users.*') -&gt;join('groups g', 'g.id = users.group_id') -&gt;join('profiles', 'profiles.user_id = users.id', 'left') -&gt;group_by('users.id'); $this-&gt;db-&gt;order_by('users.created_on', 'ASC'); $this-&gt;db-&gt;limit($limit); $results = $this-&gt;db-&gt;get('users')-&gt;result_array(); return $results; } </code></pre> <p>Here is the controller function...</p> <pre><code>function get_oldest() { $this-&gt;load-&gt;model('user_account/user_account_m'); $limit = $this-&gt;attribute('limit'); $user_id = $this-&gt;current_user-&gt;id; $users = $this-&gt;user_account_m-&gt;get_oldest($limit, $user_id); return $users; } </code></pre> <p>The "Follower"(default_follow) table in the sql database has the following structure...</p> <blockquote> <p><strong>id</strong> = the id of the follow event<br> <strong>follower_id</strong> = the user_id of the person who is doing the following<br> <strong>followed_id</strong> = the user_id of the person being followed</p> </blockquote> <p>The "Profile"(default_profiles) table in the sql database has the following structure...</p> <pre><code>user_id display_name first_name last_name </code></pre> <p>I know I need to use the current user's id in some way to get this to work, I'm just having a hard time figuring out how. Thanks in advance for your help people.</p>
 

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