php - How to join 3 tables in codeigniter -


i have 3 tables:

tbl_events --> primary key = event_id

tbl_event_bids --> (event_id in no primary key)

tbl_users --> primary key = u_id

i want these fields:

tbl_events --> added_date

tbl_events --> bid_end_date

tbl_events --> event_date

tbl_event_bids --> bid_amount

tbl_users --> u_fname

tbl_users --> u_lname

there no error array empty. there error in code? please help...

public function get_confirmed_events($loged_user_id){      $this->db->select(' tbl_events.event_name,                         tbl_events.added_date,                         tbl_events.bid_end_date,                                                     tbl_events.event_date,                          tbl_event_bids.bid_amount,                          tbl_users.u_fname,                         tbl_users.u_lname');      $this->db->where('tbl_events.u_id', $loged_user_id);     $this->db->where('tbl_events.closed_bid', 'n');      $this->db->where('tbl_event_bids.bid_statues', 'w');              $this->db->join('tbl_event_bids', 'tbl_events.event_id = tbl_event_bids.event_id');     $this->db->join('tbl_users', 'tbl_events.u_id = tbl_users.u_id');      $data = $this->db->get('tbl_events');      $confirmed_result = $data->result();      return $confirmed_result;   } 

try 1

public function get_confirmed_events($loged_user_id){ $this->db->select(' tbl_events.event_name,                     tbl_events.added_date,                     tbl_events.bid_end_date,                                                 tbl_events.event_date,                     tbl_event_bids.bid_amount,                     tbl_users.u_fname,                     tbl_users.u_lname');       $this->db->join('tbl_event_bids', 'tbl_events.event_id = tbl_event_bids.event_id','left'); $this->db->join('tbl_users', 'tbl_events.u_id = tbl_users.u_id','left'); $this->db->where('tbl_events.u_id', $loged_user_id); $this->db->where('tbl_events.closed_bid', 'n'); $this->db->where('tbl_event_bids.bid_statues', 'w');  $data = $this->db->get('tbl_events'); $confirmed_result = $data->result(); return $confirmed_result; } 

i have used left join if want join other can specify in third parameter of join() see query how looks echo $this->db->last_query();


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -