nickholt1972 Posted September 24, 2006 Share Posted September 24, 2006 THE PROBLEM: I'm developing an online shop using PHP and MySQL. I've got products and each product might have different sizes, colours, etcI have two tables: products and productdetailsWhen i list these in my shop I want it to say (e.g.)Product 1:Colour: white, Size: smallColour white, Size: largeBut what i'm getting isProduct 1:Colour: white, Size: smallProduct 1:Colour white, Size: largeThis is my SQL Query and the PHP to output it:$result = @mysql_query('SELECT products.id, products.productid, products.productname, productdetails.id, productdetails.size FROM productdetails RIGHT JOIN products ON products.productid = productdetails.productid');// Display the text of each entry in a table while ($row = mysql_fetch_array($result)) { echo '<div id="newproduct"><table border="1">' . '<tr><td>' . $row['id'] . '</td><td>' . $row['productid'] . '</td><td>' . $row['productname'] . '</td></tr>' . '<tr><td>' . $row['size'] . '</td></tr></table></div>';}I'm pretty sure its not the MySQL query, I've also tried [i]FROM products, productdetails WHERE products.productid = productdetails.productid[/i]but it doesn't solve my problemI'm sure its very simple, it usually is. Any help would be greatly appreciated.Thanks,Nick Link to comment https://forums.phpfreaks.com/topic/21863-php-mysql-display-problems/ Share on other sites More sharing options...
onlyican Posted September 24, 2006 Share Posted September 24, 2006 I just built something which grabs details from the database, and each time the supplier is different, I wanted the supplier in a headingSo what I done is something like this[code]<?php//Add on the end of your query//ORDER BY productname//then your while loopwhile($row = ......){if($prod_name != $row["product_name"]){echo $row["product_name"]."<br />\n";}$prod_name = $row1["product_name"];//Continue with your results}?>[/code] Link to comment https://forums.phpfreaks.com/topic/21863-php-mysql-display-problems/#findComment-97636 Share on other sites More sharing options...
ronverdonk Posted September 24, 2006 Share Posted September 24, 2006 Maybe this is what you are loo0king for, I had to guess what each field is.[code]$oldid = "";echo '<div id="newproduct"><table border="1">';while ($row = mysql_fetch_array($result)) { if ($oldid != $row['productid']) { echo '<tr><td>' . $row['id'] . '</td>' . '<td>' . $row['productid'] . '</td>' . '<td>' . $row['productname'] . '</td>' . '</tr>'; $oldid = $row['productid']; } '<tr><td>' . $row['size'] . '</td>' . '</tr>';}echo '</table></div>';[/code]Ronald 8) Link to comment https://forums.phpfreaks.com/topic/21863-php-mysql-display-problems/#findComment-97639 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.