Order your results by series_id
, so all the products with the same value will be together.
$stmt = $pdo->prepare("SELECT series_id, product_name
FROM yourTable
ORDER BY series_id");
$stmt->execute();
Then when displaying the results, show the Series header and start a new
whenever it changes:
$last_series = null;
echo "\n";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
if ($row['series_id'] != $last_series) {
if ($last_series) {
echo "
\n";
}
echo "" . $row['series_id'] . " Series Product\n";
echo "\n";
$last_series = $row['series_id'];
}
echo "- " . $row['product_name'] . "
\n";
}
if ($last_series) {
echo "
\n";
}
echo "\n";