Group multiple mysql result by one column value

后端 未结 1 655
小鲜肉
小鲜肉 2021-01-28 23:28

I\'m trying to fetch all results form mysql table and convering to Json format. Each row may contain a common column value(movie_name). I want to group results by that common fi

相关标签:
1条回答
  • 2021-01-29 00:10
    $json_arr = array("movies"=>array());
    foreach ($slots as $slot) {
        $json_arr['movies'][$slot["movie_name"]]['movie_name'] = $slot["movie_name"];
        $json_arr['movies'][$slot["movie_name"]]['slots'][] = array (
            "slot_id" => $slot["slot_id"],
            "screen_id" => $slot["screen_id"],
            "time" => $slot["time"],
            "price" => $slot["price"]
        );
    }
    
    0 讨论(0)
提交回复
热议问题