Check that two users are friends together in php/mysql -


i have searched before asking, popular answer before can't project

table struct

users table

userid | username

1|user1 2|user2 3|user3 4|user4 5|user5 6|user6 

friend table

requestuserid | targetuserid

1|3 1|4 1|6 3|2 3|5 2|4 2|1 

now ok, problems is:

if userid 1 haved relation userid 2 store in users table like:

1|2 

and not store duplicate like

1|2 2|1 

now need check user-x friend user-y, if 2 friend php return true, false else. possible if database stored duplicate 1|2 , 2|1, no :(

how can 1 query ?

you'd using or.

select 1 friends (requestuserid = :id1 , targetuserid = :id2) or (requestuserid = :id2 , targetuserid = :id1)

this query return empty set on failure, , 1 on success.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -