【发布时间】:2017-06-06 00:10:05
【问题描述】:
我正在尝试检索在 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;
}
【问题讨论】: