Jump to content

Question about Multiple SQL Queries....


about2flip

Recommended Posts

Hi:

 

I need to query some data from multiple tables. I have the first set of tables working but can't seem to get a grasp on pulling my second query. I'm learning SQL, and PHP and really need some help. I need to query my soupsandsalads table, and then place them underneath the table I have prepared for the data to show up. here is what I am using, and here is the site where it is....http://freshfreshseafood.com/test/soupssalads.php

 

Thanks for your help.

 

//select a database to work with

$selected = mysql_select_db("menus",$dbhandle) or die("Could not select menus");

 

$result = mysql_query("SELECT id, appetizer600pp, appetizer475pp FROM appetizers");

//echo mysql_num_rows($result) . '<br>';

//Sif($result){ echo '1'; } else { echo '2'; }

 

// Print the titles

echo '<table width="65%" border="0" cellspacing="2" cellpadding="0">

  <tr>

    <td width="100" height="3" align="left"><strong>Appetizers $6.00 Per Person</strong></td>

    <td width="100" height="3" align="left"><strong>Appetizers $4.75 Per Person</strong></td>

  </tr>',"\n";

 

//fetch tha data from the database

while ($row = mysql_fetch_array($result)) {

echo '<tr><td width="160" height="3" align="left">'.$row['appetizer600pp'].'</td>

      <td width="250" height="3" align="left">'.$row['appetizer475pp'].'</td></tr>',"\n";

}

echo '</table><br>';

 

 

echo '<table width="730" border="0" cellspacing="0" cellpadding="0">

<tr>

    <td width="200" height="3" align="left"><strong>Soups and Salads</strong></td>

    <td width="100" height="3" align="left"><strong>Price</strong></td>

  </tr>',"\n";

//close the connection

mysql_close($dbhandle);

?>

Link to comment
https://forums.phpfreaks.com/topic/138031-question-about-multiple-sql-queries/
Share on other sites

There's only one query for appetizers shown here.  Are soups and salads in the same table?  If they are then you need to distinguish them from appetizers to be able to extract what you want.  If they are in a separate table then you just need a second query like you did the first.

I figured it out. Not sure if my coding is correct, but it is displaying how I want it. Is there an easier way than what I did: Use the link above to see my results. Thanks

 

//select a database to work with

$selected = mysql_select_db("menus",$dbhandle) or die("Could not select menus");

 

$result = mysql_query("SELECT id, appetizer600pp, appetizer475pp FROM appetizers");

//echo mysql_num_rows($result) . '<br>';

//Sif($result){ echo '1'; } else { echo '2'; }

 

// Print the titles

echo '<table width="65%" border="0" cellspacing="2" cellpadding="0">

  <tr>

    <td width="100" height="3" align="left"><strong>Appetizers $6.00 Per Person</strong></td>

    <td width="100" height="3" align="left"><strong>Appetizers $4.75 Per Person</strong></td>

  </tr>',"\n";

 

//fetch tha data from the database

while ($row = mysql_fetch_array($result)) {

echo '<tr><td width="160" height="3" align="left">'.$row['appetizer600pp'].'</td>

      <td width="250" height="3" align="left">'.$row['appetizer475pp'].'</td></tr>',"\n";

}

echo '</table><br>';

 

$result = mysql_query("SELECT id, soupandsalad, price FROM soupsandsalads");

 

echo '<table width="730" border="0" cellspacing="0" cellpadding="0">

<tr>

    <td width="200" height="3" align="left"><strong>Soups and Salads</strong></td>

    <td width="100" height="3" align="left"><strong>Price</strong></td>

  </tr>',"\n";

while ($row = mysql_fetch_array($result)) {

echo '<tr><td width="160" height="3" align="left">'.$row['soupandsalad'].'</td>

      <td width="250" height="3" align="left">'.$row['price'].'</td></tr>',"\n"; 

//close the connection

mysql_close($dbhandle);

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.