Just wondering if someone can help with a problem I am having and/or maybe point me in the right direction. I have a mysql query that returns quite a bit of data that I need formatted and displayed in a web browser. While I can get each row displayed on it's own with a while loop, I need to group the redundant data while still showing the relevant per line data in each group. Here is the code:
// Now we are going to query the database
$sql = "select
Wheel_Brand.Wheel_Brand as brand,
Wheel_Style.Wheel_Style_Name as style,
Wheel_Finish.Finish as finish,
Wheel_Dimension.Dimension as size,
Wheel_Fitment.Fitment as fitment,
Wheel_Product.Price as price
from Wheel_Product, Wheel_Brand, Wheel_Dimension, Wheel_Finish, Wheel_Fitment, Wheel_Style
where Wheel_Brand.ID = $linkterm
and Wheel_Product.Brand_ID = Wheel_Brand.ID
and Wheel_Product.Wheel_Style_ID = Wheel_Style.ID
and Wheel_Product.Wheel_Finish_ID = Wheel_Finish.ID
and Wheel_Product.Wheel_Dimension_ID = Wheel_Dimension.ID
and Wheel_Product.Wheel_Fitment_ID = Wheel_Fitment.ID";
$result = mysql_query($sql);
//Just a little something to keep track of the number of results.
$num_results = mysql_num_rows($result);
// Here I will also print the number.
echo '<p>Number of results returned: '.$num_results.'</p>';
// Here is where we check for results and die if nothing comes back
if (!$result)
{
echo "DB Error, could not query the database\n";
echo 'MySQL Error: ' . mysql_error();
exit;
}
while ($row = mysql_fetch_assoc($result))
{
echo '<table width="100%"></tr><td width="100px">';
echo '<img src="" alt="Wheel Image" />';
echo '</td><td>';
echo 'Brand: '.$row['brand'];
echo '<br />';
echo 'Style: '.$row['style'];
echo '<br />';
echo 'Finish: '.$row['finish'];
echo '</td><td>';
echo 'Fitment';
echo '<br />';
echo $row['fitment'];
echo '</td><td>';
echo 'Wheel Size';
echo '<br />';
echo $row['size'];
echo '</td><td>';
echo 'Price Each';
echo '<br />';
echo $row['price'];
echo '</td></tr></table>';
}
That brings back the following page:
dev.tireandwheeldeals.com/customwheel.php?brand=9
As you can see the wheel style Cool Down has 3 different possible sizes with prices, while all of the information on the Cool Down is exactly the same. What I would like is to get the output where all of the Brand, Style, and Finish that are the same show up as one while to the right the different sizes then go in the last 3 columns.
So can this be done from within the current while loop, or does it require more code and formatting, and if so is it too much help to ask for here ;-)