這是我的第一個表如何在多表中選擇mysql並混合到一個json中?
SELECT * FROM tb_chat WHERE senderid = "1"
輸出:
{
"id":"5",
"itemid":"43",
"senderid":"1",
"receiverid":"11",
"sendtime":"2015-10-04 23:31:35",
"sendcontent":"1232342sdfsasg",
"remark":null
}
這是我的第二個表
SELECT * FROM `tb_user` WHERE id = "1"
輸出
{
"id":"1",
"username":"hksfho",
"password":"ae6e16c74efb51b616b0d4f7151aff88",
"email":"[email protected]",
"installationId":"E705A03522F3E85768581A7222AC40F6"
}
我想混2噸ABLES在一個JSON使用PHP 的tb_chat.senderid = tb_user.userid
向我們展示你的努力,你有什麼到目前爲止已經試過?爲此,您必須逐個迭代第二個查詢並將其與其父級合併。或者如果您使用任何'ORM',這很容易實現。 – Manwal
@MahaDev我想輸出的圖片 – hksfho
$ final_result = new array(); $ final_result = $ query1_result; $ final_result ['senderid'] = $ query2_result; json_encode($ final_result); –