Hi guys i am trying to create a multi dimensional array as the format bellow but i am struggling to do so, any help would be appreciated. Thank you.
$movies = array();
$sql = "SELECT u.username AS Username, group_concat(v.title) AS Video_title, group_concat(r.rate) AS Rating
FROM `rating` AS r
JOIN `uploads` AS v ON r.video_id = v.vid_id
JOIN `users` as u ON u.user_id = r.rater_id
GROUP by Username" ;
$query = mysqli_query($conn, $sql);
while($result = mysqli_fetch_assoc($query)){
$movies[] = $result;
}
foreach($movies as $k => $v){
unset($movies[$k]);
$movies[$v['Username']] = $v;
}
foreach($movies as $k => $v){
unset($movies[$k]['Username']);
}
print_r($movies);
This is what i am currently getting:
[user1] => Array ( [Video_title] => Snakes on the Plane,
Superman Returns,
The Night Listner,
Lady in the Water,
Just my Luck,
You me and Dupree
[Rating] => 3.5,
3.5,
3,
2.5,
3,
2.5
) )
But i am aiming to output it in the following format:
'user1' =>
array('Lady in the Water' => 2.5,
'Snakes on a Plane' => 3.5,
'Just My Luck' => 3.0,
'Superman Returns' => 3.5,
'You, Me and Dupree' => 2.5,
'The Night Listener' => 3.0
)