nazca Posted June 15, 2006 Share Posted June 15, 2006 Hope this is better explanation than before.... big ooops [img src=\"style_emoticons/[#EMO_DIR#]/unsure.gif\" style=\"vertical-align:middle\" emoid=\":unsure:\" border=\"0\" alt=\"unsure.gif\" /] Here is the following code I am using now. This table displays the following heading first:Name Description PriceUnder the heading the query displays all the food items ordered by sectionOrder for a particular restaurant. This is fine, but I want to be able to print category names with its corresponding food items under it such as appetizers, salads, main course, etc... So the food menu would say :AppetizersQuesadilla great mexican dish $3.99Wings 10 drumsticks $6.99SaladsChef fresh greens $6.99Caesar romaine greens $7.99Main Courseetc, etc, etcThe code below just displays all the food items from a particular restaurant ordered by section:Quesadilla " "Wings " "Chef SaladCasear Saladetc.You can imagine if the menu is huge how annoying it would be to find a salad, or main course....<table width="750" border="2" cellspacing="0" cellpadding="0" bordercolor="#FFFFFF"> <tr> <td> <?php include "admin/db_conn_open.php"; $query = mysql_query("SELECT pName, pDescription, pPrice, pSection, sectionID, sectionOrder, sectionName FROM products, sections WHERE pSection=sectionID ORDER BY sectionOrder"); print ("<tr>"); print ("<td width='200' >Name</td>"); print ("<td width='490' >Description</td>"); print ("<td width='60' >Price</td>"); print ("</tr>"); while ($row = @mysql_fetch_array($query)) { $variable1=$row["pName"]; $variable2=$row["pDescription"]; $variable3=$row["pPrice"]; //table layout for results print ("<tr>"); print ("<td width='200' >$variable1</td>"); print ("<td width='490' >$variable2</td>"); print ("<td width='60' >$$variable3</td>"); print ("</tr>"); } ?> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/12100-mysql-category-re-vised-to-make-sense/ Share on other sites More sharing options...
Barand Posted June 15, 2006 Share Posted June 15, 2006 Try[code]$query = mysql_query("SELECT pr.pName, pr.pDescription, pr.pPrice, sc.sectionName FROM products pr INNER JOIN sections sc ON pr.pSection = sc.sectionID ORDER BY sc.sectionOrder"); print('<table width="750" border="2" cellspacing="0" cellpadding="0" bordercolor="#FFFFFF">');print ("<tr>");print ("<td width='200' >Name</td>");print ("<td width='490' >Description</td>");print ("<td width='60' >Price</td>");print ("</tr>");$last_section = '';while (list($name, $desc, $price, $section) = @mysql_fetch_row($query)){ if ($last_section != $section) { print "<tr><td colspan='3'><H3>$section</H3></td></tr>"; } print ("<tr>"); print ("<td>$name</td>"); print ("<td>$desc</td>"); print ("<td>$price</td>"); print ("</tr>"); $last_section = $section;}print '</table>';[/code] Link to comment https://forums.phpfreaks.com/topic/12100-mysql-category-re-vised-to-make-sense/#findComment-46110 Share on other sites More sharing options...
nazca Posted June 15, 2006 Author Share Posted June 15, 2006 To Barand: I tried the code and it works.... I have asked my C+ programmer friend and no luckYou save me a lot of time.......... Super Thanks Link to comment https://forums.phpfreaks.com/topic/12100-mysql-category-re-vised-to-make-sense/#findComment-46114 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.