Jump to content

Recommended Posts

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 Price

Under 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 :

Appetizers
Quesadilla great mexican dish $3.99
Wings 10 drumsticks $6.99
Salads
Chef fresh greens $6.99
Caesar romaine greens $7.99
Main Course
etc, etc, etc

The code below just displays all the food items from a particular restaurant ordered by section:
Quesadilla " "
Wings " "
Chef Salad
Casear Salad
etc.


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

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]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.