I have a mysql table with these columns:
series_id, series_color, product_name
In the output, I want to list the data by sections, one section perseries_id
like this:
A12 Series Product - Milk - Tea - sugar - water B12 Series Product - Water - Banana - Cofee - Tea
Sort the results by
series_id
so all products with the same value will be together.Then, when displaying the results, display the series title and start a new one if it changes
:
\n"; while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { if ($row['series_id'] != $last_series) { if ($last_series) { echo "
\n"; } echo "\n"; $last_series = $row['series_id']; } echo "- " . $row['product_name'] . "
\n"; } if ($last_series) { echo "