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

Hello 
am trying to get all my friends from database i have a table called friends it has id, user_one, user_two and date
now i used this code and i was getting them but i couldn't get the date from friends
here is the code:
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){
          $query $CI->db->get_where('users', array('user_id' => $row['user_two']));
          $results $query->result_array();
          array_push($return_data$results);
      }else{
          $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();
  }



so to get all the friends with the date in which they became friends i used this code:

PHP Code:
function getfriends($my_id){
  $CI =& get_instance();
  $where "user_one ='".$my_id."' OR user_two = '".$my_id."'";
  $CI->db->where($where);
  $query $CI->db->get('friends');
  $CI->db->select('*');
  $CI->db->from('friends');
  $CI->db->join('users as b''friends.user_id = b.user_id''LEFT OUTER');
  $CI->db->join('users as c''friends.user_id = c.user_id' 'LEFT OUTER');
  $query $CI->db->get();
  return $query->result_array();

i have two friends but it returns 1 friend and me, i only want the 2 friends
can anyone help please.
Thanks in advance
Reply


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



Theme © iAndrew 2016 - Forum software by © MyBB