stualk Posted January 8, 2009 Share Posted January 8, 2009 I'm trying to work out how best to display products from a db but i'm having difficulty with my select statement. Here's an example of part of the db: id product fabric colour 1 square leather cream 2 square leather black 3 square leather white 4 square suede cream 5 round leather black 6 round leather white 7 round suede cream 8 round suede white What I want to do is for someone to be able to view the page containing the square products, the select statement then calls out the first fabric option (leather) and then displays the colour options beneath, like this Square products: Leather Available in: cream | black | white Suede Available in: cream Am I going to need an array here or is there an easier way to do this? Quote Link to comment Share on other sites More sharing options...
divadiva Posted January 8, 2009 Share Posted January 8, 2009 Define sql query .Once you have that create a table and define different rows in them. I hope it helps. Quote Link to comment Share on other sites More sharing options...
stualk Posted January 8, 2009 Author Share Posted January 8, 2009 Thanks - I'm not certain. Take a look at the code I've been using. I've already created the table, it's just displaying the results i'm having difficulty with: require ('database.php'); $query2 = mysql_query("select DISTINCT fabric from TABLE where product = '$product'"); while($rst = mysql_fetch_array($query2)) { echo(" <tr> <td class='body'> <b>$rst[fabric]</b><br>Available in: $rst[colour] </td> </tr> "); } Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted January 8, 2009 Share Posted January 8, 2009 here is your code cleaned up a bit <?php require ('database.php'); $query2 = mysql_query("select DISTINCT fabric, colour from TABLE where product = '$product'")or die(mysql_error()); while($rst = mysql_fetch_array($query2)) { echo '<tr>'; echo '<td class="body">' echo '<b>' . $rst['fabric'] . '</b><br>Available in: ' . $rst['colour']; echo '</td>'; echo '</tr>'; } ?> **made a few edits after re reading my code Quote Link to comment Share on other sites More sharing options...
stualk Posted January 9, 2009 Author Share Posted January 9, 2009 That's fine, cheers. This is almost working how I want it to. However, using the code above it displays the products like this: Leather Available in: Black Leather Available in: Cream Leather Available in: White Ideally I want it to display like this: Leather Available in: Black, Cream, White How can I best achieve this? Please don't say it's an array as I can never get my head around them!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.