php - Joining multiple SQL queries to display online friends list? -
i trying join 3 tables display list of table users
taken table subscribers
ip = ip in table online
.
subscribers
table: (doesn't allow duplicates, type
tells if or not other user subscribed back.)
sender recipient 1 5 5 3
users
table:
id loginip 1 192.168.0.1 3 192.168.0.2 5 192.168.0.3
online
table:
ip 192.168.0.1 192.168.0.2 192.168.0.5
so query should grab id
's, find loginip
of id
's , scan online
table , return online users: (assuming userid = 5)
sender recipient send_ip reci_ip 5 3 192.168.0.3 192.168.0.2 1 5 192.168.0.1 192.168.0.3
i need figure out way cut ip if user = 5, not display on list. can myself after 1 of fine people me out bit. :)
my attempt, although poor:
select f.sender friend1, f.recipient friend2, u1.loginip ip1, u2.loginip ip2 subscribers f inner join users u1 on u1.id = f.sender inner join users u2 on u2.id = f.recipient inner join online o1 on o1.ip = u1.loginip inner join online o2 on o2.ip = u2.loginip f.sender = 5 or f.recipient = 5;
thank you.
update: must tired, because works? i'm sorry.
the correct answer contained in question. i'm posting question doesn't appear unanswered.
select f.sender friend1, f.recipient friend2, u1.loginip ip1, u2.loginip ip2 subscribers f inner join users u1 on u1.id = f.sender inner join users u2 on u2.id = f.recipient inner join online o1 on o1.ip = u1.loginip inner join online o2 on o2.ip = u2.loginip f.sender = 5 or f.recipient = 5;
Comments
Post a Comment