Hi
I need some help with this code........
$result = mysql_query("SELECT Distinct SubProduct, Product FROM Table Order by PRODUCT");
while($row = mysql_fetch_array($result))
{
echo " " .$row['Product']. " ";
echo " " .$row['SubProduct']. " ";
}
This gives me the following output
Products 1 SubProduct 1
Products 1 SubProduct 2
Products 1 SubProduct 3
Products 1 SubProduct 4
Products 2 SubProduct 1
Products 2 SubProduct 2
Products 2 SubProduct 3
Products 2 SubProduct 4
However I would like to display the information this way with the Product name only displaying once like this
Product 1
SubProduct 1 SubProduct 2 SubProduct 3 SubProduct 4
Product 2
SubProduct 1 SubProduct 2 SubProduct 3 SubProduct 4
Can anoyone show me what I need to do the the code to get my information to display the way I want it?
Code Help
Moderator: General Moderators
Re: Code Help
A quick and dirty fix? try this
Code: Select all
$result = mysql_query("SELECT Distinct SubProduct, Product FROM Table Order by PRODUCT");
$product_name = "";
while($row = mysql_fetch_array($result)) {
if($product_name != $row['Product']) {
$product_name = $row['Product'];
echo "<h3>$product_name</h3>";
}
echo "{$row['SubProduct']} ";
}
Re: Code Help
infolock thanks very much, exactly what I needed.
Cheers!!!
Cheers!!!