I use the following two methods to get a listing with services which should be grouped by service
public function get_services()
{
$sql = "SELECT service_id
, service
, omschijving
, footnote
FROM services
ORDER BY service";
$stmt = $this->pdo->query($sql);
return $stmt->fetchAll();
}
public function get_services_prijzen()
{
$sql = "SELECT service_id
, service_omschrijving
, service_prijs
FROM services_prijzen
ORDER BY service_id, service_omschrijving"
$stmt = $this->pdo->query($sql);
$prijzen = $stmt->fetchAll();
$prijzen = array();
foreach ($prijzen as $row)
{
if (!is_array($prijzen[$row['service_id']]))
{
$prijzen[$row['service_id']] = array();
}
$prijzen[$row['service_id']] = $row;
}
return $prijzen;
}
And I have the following in the View:
<?php foreach ($services as $service): ?>
<h2><?php echo $service['service']; ?></h2>
<?php foreach ($prijzen[$service['service_id']] as $prijs): ?>
<p><?php $prijs['service_omschrijving']; ?><span><?php $prijs['service_prijs']; ?></span></p>
<?php endforeach; ?>
<?php endforeach; ?>
But I keep getting the error messages as in the subject:
Undefined offset: 1 en Invalid argument supplied for foreach() on Line 6
which is this:
<?php foreach ($prijzen[$service['service_id']] as $prijs): ?>
What am I doing wrong?