I am putting together a list of service providers. I would like them to be listed like:
Plumber: Joe's Plumbing Mike's Plumbing
Electrician: Scott electric John electric
etc...
How can I pull and group this information from my query. Also when I try to call pt.name it says it is NULL any ideas why?
Thanks
$qry = "SELECT pt.name, p.name, p.phone
FROM provider_type AS pt
LEFT JOIN providers_provider_type AS ppt ON pt.id = ppt.provider_type_id
LEFT JOIN providers AS p ON ppt.providers_id = p.id
WHERE installation_id = $installation_id
GROUP BY ppt.provider_type_id";
//$qry = "SELECT * FROM providers WHERE installation_id = $installation_id";
$res = mysqli_query($mysqli, $qry) or die('-1'.mysqli_error($mysqli));
$categories = array();
while ($row_rsCategories = mysqli_fetch_assoc($res)) {
///////////////////////////////////////////////
$categories[] = array(
'id' => $row_rsCategories['id'],
'provider_type' => $row_rsCategories['pt.name'],
'provider_name' => $row_rsCategories['name']
);
}
?>
<div class="container">
<div class="content">
<?php if ($msgBox) { echo $msgBox; } ?>
<div class="row">
<?php var_dump($categories); ?>
<?php if (empty($categories)) { ?>
<div class = "big-icon">
<i class="fa fa-meh-o fa-5x"></i>
</div>
<p><center>Sorry! It looks like we don't have a Scout in this area. <br />
Please check back in as we continue to add new Scouts to the network all the time.</center></p>
<?php } else {
?>
<table class="table table-striped">
<tr>
<th>Type</th>
<th>Name</th>
<th>Phone</th>
<th>More Info</th>
</tr>
<?php foreach ($categories as $category) { ?>
<tr>
<td><?php echo $category['provider_type']; ?> </td>
<td><?php echo $category['provider_name']; ?> </td>
<td> </td>
<td> </td>
</tr>
<?php }
}
?>
</table>