I have two column table friends table where it has a recode of users whos friends with eacho other. i want to get a list who’s friends with a specific user. to do that i wrote a sql query as such and got a result..
SELECT *
FROM `friends`
WHERE `user_idf` = '2'
OR `user_idff` = '2'
++ user_idf ++++ user_idff+++
2 + 1
3 + 2
4 + 2
2 + 5
+++++++++++++++++++++++++++
how to write a php function to echo user who’s a friend of 2 (this i will replace with a POST where it gets user id from an application)
i.e.
1, 3, 4, 5
do you mean something like this?
Im not great with sql to be honest, but I think union is what you are looking for (and I think my syntax is correct although im not 100%).
This should from my understanding take the user ids of anyone who is friends with user 2 and output it. The union of results returned when user 2 is in
user_idfanduser_idffcolumns.EDIT: Actually I still stand by my answer, if you don;t do this sql side then you will have to have a more complex PHP function.
For the PHP itself look into mysqli and PDO as your two main options for prepared statements.