Welcome Guest, Not a member yet? Register   Sign In
Mysql get values from table with join (or and) ?
#4

Thanks for your help i have rewritten my code so that i pass ony one query to get the results this seems to work or though havnt completely tested it in thourough.

my code here.

Code:
$where = "user_messages.msg_user_id = $user_id OR user_buddys.bud_one_id = $user_id OR user_buddys.bud_two_id = $user_id ";
        $wherestat = "user_buddys.bud_status= '1'";
        $this->db->select('user_accounts.uacc_id, user_accounts.uacc_username, user_profiles.pro_uacc_fk, user_profiles.pro_birthday,
        user_profiles.pro_town, user_messages.msg_id,etc.........) ;
        
        $this->db->join('user_buddys', 'user_messages.msg_user_id = user_buddys.bud_one_id OR user_messages.msg_user_id = user_buddys.bud_two_id');
        $this->db->join('user_profiles', 'user_profiles.pro_uacc_fk = user_accounts.uacc_id');

        $this->db->group_by ('user_messages.msg_id');
        $this->db->order_by ('user_messages.msg_id','desc');
        $this->db->where($where);
        $this->db->where($wherestat);
      

        $result = $this->db->get();
        if ($result->num_rows() > 0):
            return $result->result();
        else:
            return false;
        endif;
         return $query->result();

i don't seem to see why i should have an extra table ?
surely i can query my buddies table to find friends of friends using and 'OR' and 'AND'
i already query this table to find out if a profile page i'm on is a friend of mine or not by

Code:
$query = $this->db->query("SELECT bud_one_id, bud_two_id, bud_status FROM user_buddy WHERE bud_status = '1' AND (bud_one_id = $user_id OR bud_two_id = $user_id) AND (bud_one_id = $freindid OR bud_two_id = $freindid)");

please explain thx
Reply


Messages In This Thread
RE: Mysql get values from table with join (or and) ? - by Marcel - 02-28-2015, 01:30 AM



Theme © iAndrew 2016 - Forum software by © MyBB