I have searched this for hours and read numerous q/a's on foreach loops and while loops for the answer to my question but have yet to find a response that resembled my query. Mostly categorized menues...
I have a mysql table setup like this
cat | product | link | status
1 | milk | https | in stock
1 | eggs | https | in stock
2 | butter | https | out of stock
2 | bread | https | in stock
3 | bananas | https | in stock
and would like to group the data in a php looped table like this;
Category 1
milk | https | in stock
eggs | https | in stock
Category 2
butter | https | out of stock
bread | https | in stock
Category 3
bananas | https | in stock
What sort of nested loop would I need? would I need to call a second mysqli query in the nested loop grouping rows by cat
?
Thanks :)
PHP code added Edit
$stmt = $con->prepare("SELECT * FROM wp_products ORDER BY cat");
$stmt->execute();
$results = $stmt->get_result();
echo "<p><center><h4>Master List</h4></center></p>";
echo "<table>
<tr>
<th>Product</th>
<th>Link</th>
<th>Status</th>
</tr>";
if (mysqli_num_rows($results)>0){
while($row = $results->fetch_assoc())
{
echo "<tr><td>" . $row['product'] ."</td>";
echo "<td>". $row['link'] ."</td>;
echo "<td>". $row['status'] ."</td></tr>";
}
}
echo "</table>";