我正在尝试检索ios应用程序中的好友请求的用户,并将他们返回到应用程序中的好友请求列表中。为此,我使用了一个PHP函数,该函数在通知表中查询发送通知的user_id,然后返回所有与特定通知类型匹配并标记为未读的行。然后,我想查询我的用户表,并将发送请求的用户返回到这个特定的user_id。下面是我构建的代码:
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;
}发布于 2018-04-06 15:36:06
如果我没理解错的话,那么您的问题只是一个sql问题,这个查询应该返回预期的用户:
SELECT u.*
FROM tblUser AS u
LEFT JOIN tblNotification AS n
ON u.user_id = n.notification_from_id
WHERE n.notification_to_id = :user_id
AND n.notification_type = 3
AND n.notification_is_read = 0
AND n.notification_from_id <> :not_from_idhttps://stackoverflow.com/questions/44379519
复制相似问题