Welcome Guest, Not a member yet? Register   Sign In
Help with join query
#1

(This post was last modified: 05-30-2016, 08:31 PM by agrc.)

I'm having problems with a join query.

I want to have a set of results if a user is logged in and another set of results consisting of two tables if they are not logged in.

I have this query

Code:
$this->db->from('projects');

      // If specific user projects
      if($this->session->userdata('user_id')) :

          $this->db->where('user_id', $this->session->userdata('user_id'));

      // Otherwise, public projects with user data
      else :

           $this->db->join('users', 'users.id = projects.user_id');

      endif;      

      $this->db->where('status', $status);

      $this->db->limit($limit, $offset);

      $this->db->order_by('id', 'desc');

      $query = $this->db->get();

I'm getting a MySQL ambiguous error and don't know how to fix this.

Help appreciated, agrc
Reply


Messages In This Thread
Help with join query - by agrc - 05-30-2016, 08:21 PM
RE: Help with join query - by kilishan - 05-30-2016, 08:47 PM
RE: Help with join query - by agrc - 05-31-2016, 04:52 PM
RE: Help with join query - by kilishan - 05-31-2016, 05:54 PM



Theme © iAndrew 2016 - Forum software by © MyBB