Welcome Guest, Not a member yet? Register   Sign In
inner join with OR using codeigniter
#3

(This post was last modified: 09-24-2019, 02:13 PM by tp45.)

(09-24-2019, 01:27 PM)Wouter60 Wrote:
Quote:i have a table called friends it has id, user_one, user_two and date

What do you use 'user_one' and 'user_two' for? That's not clear to me.
user_one is the current user_id and user_two is the other user which is a friend with the user_id, but the current user myth be user_two
and user_one myth be the other user vise versa depending on who befriended who.
 it is a friendship system.

ok i did this and it worked i dont know if it will give me problems in the near future 
PHP Code:
function getfriends($my_id$send_data){

  $CI =& get_instance();
  $where "user_one ='".$my_id."' OR user_two = '".$my_id."'";
  $CI->db->where($where);
  $query $CI->db->get('friends');
  //die(print_r($query->result_array()));
  $all_users $query->result_array();
  $return_data = [];

  if ($send_data) {
    foreach($all_users as $row){
      if($row['user_one'] == $my_id){
          $CI->db->join('friends''friends.user_two = users.user_id');
          $query $CI->db->get_where('users', array('user_id' => $row['user_two']));
          $results $query->result_array();
          array_push($return_data$results);
      }else{
          $CI->db->join('friends''friends.user_one = users.user_id');
          $query $CI->db->get_where('users', array('user_id' => $row['user_one']));
          $results $query->result_array();
          array_push($return_data$results);
      }
    }
    return $return_data;

  }else{
    return $query->num_rows();
  }


Reply


Messages In This Thread
inner join with OR using codeigniter - by tp45 - 09-24-2019, 11:41 AM
RE: inner join with OR using codeigniter - by tp45 - 09-24-2019, 01:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB