Coba kueri semua baris pada JOIN
dan kemudian iterasi untuk merender ke multi-dimensi:
$query = "SELECT *, materials.id AS material_id FROM job_truck JOIN job_truck_material ON job_truck_material.job_truck = job_truck.id JOIN materials ON job_truck_material.material = job_truck_material.id";
$jobs = array();
foreach ($conn->query($query ) as $row) {
$job_id = $row['jobid'];
$truck_id = $row['truck_id'];
if(empty($jobs[$job_id])) {
$jobs[$job_id] = array();
}
if(empty($jobs[$job_id][$truck_id])) {
$jobs[$job_id][$truck_id] = array();
}
$jobs[$job_id][$truck_id][$row['material_id']] = $row['material'];
}