Forum Moderators: coopster
id ¦ item_name ¦ item_no ¦ item_size ¦ price
23 ¦ blue shirt ¦ 1001 ¦ small ¦ $10
24 ¦ blue shirt ¦ 1001 ¦ med ¦ $11
25 ¦ blue shirt ¦ 1001 ¦ large ¦ $12
26 ¦ red shirt ¦ 1002 ¦ small ¦ $10
27 ¦ red shirt ¦ 1002 ¦ med ¦ $11
28 ¦ red shirt ¦ 1002 ¦ large ¦ $12
'id' is an auto increment column.
I want to display the data like this...
Blue shirt 1001
- small $10
- med $11
- large $12
Red shirt 1002
- small $10
- med $11
- large $12
How do I load an array and then pull out the data from the array to display it like this?
if you use
$q = "select * from products";
unless you need to reuse the data later on I would output it right away.
$query = mysql_query($q);
$lastprod = "";
while ($row = mysql_fetch_array($query)) {
if ($row['item_name']!= $lastprod) {
echo "<p>",$row['item_name']," ",$row['item_no'];
}
echo "<br>- ",$row['item_size']," ",$row['price'];
$lastprod = $row['item_name'];
}
I think that should work though I didn't test it at all.