How can I query my database to check if user_id
or friend_id
are equal to the logged in users ID and that their friendship_status
has been accepted.
Here is the MySQL code I got so far.
SELECT COUNT(id) as num
FROM users_friends
WHERE users_friends.user_id = '$user_id'
AND friendship_status = '1'
Here is my MySQL table.
CREATE TABLE users_friends (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
user_id INT UNSIGNED UNSIGNED NOT NULL,
friend_id INT UNSIGNED NOT NULL,
friendship_status TINYINT(1) UNSIGNED NOT NULL DEFAULT 0,
date_created DATETIME NOT NULL,
);