I am trying to retrieve users that were friend requested in ios app and return them into a friend request list in app. To do this I am using a PHP function that queries the notification table for the user_id it was sent from, then return all all rows that match that with a specific notification type and are marked as unread. Then I would like to query my user table and return the users who have sent the request to this particular user_id. Here is the code I have constructed:
function getSquadRequests($req, $res) {
global $db;
$user_id = validateUserAuthentication($req);
if ($user_id) {
$query = $db->prepare(
'SELECT *
FROM tblNotification
WHERE notification_to_id = :user_id
AND notification_type = 3
AND notification_is_read = 0
');
$query->bindParam(':user_id', $user_id);
if ($query->execute()) {
$user = $query->fetch(PDO::FETCH_NAMED);
// if user exist
if ($user) {
$query = $db->prepare(
'select * from tblUser where user_id = :not_from_id'
);
$query->bindParam(':not_from_id', $user['notification_from_id']);
if ($query->execute()) {
$data = $query->fetchAll(PDO::FETCH_ASSOC);
}
$newRes = makeResultResponseWithObject($res, 200, $data);
}
} else {
$newRes = makeResultResponseWithString(
$res, 400, $query->errorInfo()[2]
);
}
return $newRes;
}