Reputation: 114
This is my first table
SELECT * FROM tb_chat WHERE senderid = "1"
output:
{
"id":"5",
"itemid":"43",
"senderid":"1",
"receiverid":"11",
"sendtime":"2015-10-04 23:31:35",
"sendcontent":"1232342sdfsasg",
"remark":null
}
This is my second table
SELECT * FROM `tb_user` WHERE id = "1"
output
{
"id":"1",
"username":"hksfho",
"password":"ae6e16c74efb51b616b0d4f7151aff88",
"email":"[email protected]",
"installationId":"E705A03522F3E85768581A7222AC40F6"
}
I want to mix two tables in to one json using php the tb_chat.senderid = tb_user.userid
Upvotes: 0
Views: 481
Reputation: 1958
NO Code so a logical answer is provided , do your stuff as below-
$result =mysqli_fetch_assoc(mysqli_query(SELECT * FROM tb_chat WHERE senderid = "1"));
$result2 =mysqli_fetch_assoc(mysqli_query(SELECT * FROM `tb_user` WHERE id = "1"));
$result["senderid"]=$result2;
echo json_encode($result);
Upvotes: 2
Reputation: 5260
So, if you get the result of query in json
format, you can turn it into arrays, merge them and make it to json format again. BUT it has big overhead:
json_encode(array_merge(json_decode($firstResult, true),json_decode($secondResult, true)))
So, I think you should
get the result of query in array
, id depends what ORM you use, of whatever, how to do this.
Upvotes: 0