我有两张桌子
用户
游戏
我的要求
[
{
users:{
id: "1",
user: "user1",
games:[
{
id : "1",
game_names : "football"
}
{
id : "2",
game_names : "cricket"
}
{
id : "3",
game_names : "athletics"
}
{
id : "4",
game_names : "badminton"
}
]
}
users: {
id : "2",
user : "user2",
games :[
{
id : "3",
game_names : "athletics"
}
{
id : "4",
game_names : "badminton"
}
{
id: "5",
game_names : "basketball"
}
]
}
}
]
我现在使用的
<?php
$result = mysql_query("SELECT *,games.game_names as games
FROM users
LEFT JOIN games ON users.games=games.id
GROUP BY users.id") or die(mysql_error());
while($user = mysql_fetch_array($result, MYSQL_ASSOC)) {
$users[] = array(
'user'=>array(
'id' => $user['id'],
'user' => $user['user'],
'games' => $user['games']
)
);
}
$output = json_encode(array('statics' => $users));
echo $output;
?>
但我得到
{
statics: [
{
users: {
id: "1",
user: "user1",
games: "1,2,3,4"
}
},
{
users: {
id: "2",
user: "user2",
games: "3,4,5"
}
}
]
}
但我无法获得第二个阵列游戏
我应该如何更改我的代码 php 代码。