Zkuste zadat dotaz na všechny řádky na JOIN
a poté iterací k vykreslení do vícerozměrného:
$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'];
}