【发布时间】:2016-10-16 17:49:45
【问题描述】:
我正在获取邀请数组,对于每个邀请行的 sender_id 来自邀请行,我正在从 users 表中检索用户的详细信息。
我想在同一个邀请数组中添加用户的详细信息。我试着像这样添加。
function getInvitations()
{
$database = new Database(ContactsConstants::DBHOST,ContactsConstants::DBUSER,ContactsConstants::DBPASS,ContactsConstants::DBNAME);
$dbConnection = $database->getDB();
$stmt = $dbConnection->prepare("SELECT * FROM `Invitation` WHERE Invitation.invitee_no = ?");
$stmt->execute(array($this-> invitee_no));
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$invitations = array();
if (count($rows) > 0) {
foreach($rows as $row)
{
$stmt = $dbConnection->prepare("Select * from Users where user_id =?");
$stmt->execute(array($row['sender_id']));
$result = $stmt->fetch(PDO::FETCH_ASSOC);
$invitations[] = $row;
$invitations[] = $result;
}
$response = array("status" => 1, "message" => "Success", "Invitations" => $invitations);
return json_encode($response);
}
else {
$response = array("status"=>-1,"message"=>"Invitations list is empty");
return json_encode($response);
}
}
我得到这样的输出:
{
"status": 1,
"message": "Success",
"Invitations": [
{
"invitation_id": "369",
"date": "12/08/2016",
"invitee_no": "8655864341",
"status": "1",
"sender_id": "44"
},
{
"user_id": "44",
"user_name": "Angel",
"password": "angel",
"profile_image": "a8625093a2e95ee6b5042456b7cccc20.png",
"device_id": "eVOnz8AMVOs:APA91bHuq9Q4FLcOewUCSAQu79aZNeQsb4710k66g1MHDfZUZWa4ZcARs0SekUfnYUt5sTiKeXfFk_Gg_LdtSKk-pTAaQLxPe9UMkYG9-d-IkDRlGYxkzonQ1h2YN78S7RU0x90NAby_",
"mobile_no": "9090966666",
"email_id": "kjfhg@half.com",
"full_name": "ajjdjd",
"job_title": "sxsaca",
"home_address": "scacac",
"work_phone": "ugiuygitf",
"work_address": "bbuyiytfi"
},
]}
但我希望将这两个细节放在一个数组中。我怎样才能得到这个? 有人能帮忙吗?谢谢。。
【问题讨论】:
-
旁注:您似乎将密码存储为纯文本。 永远不要那样做 - 使用
password_hash创建一个哈希,然后使用password_verify来验证它。 -
会听从你的建议..谢谢..@FranzGleichmann
-
这条线正常吗??
String number = subObject1.getString("invitee_no"); -
是的,邀请数组字符串没有收到错误,只有用户详细信息给出错误。@nanocv
-
我猜你传递给
doPostExecute方法的response变量是JSONArray response = json_response.getJSONArray("Invitations");之类的结果,不是吗?