about2flip Posted December 22, 2008 Share Posted December 22, 2008 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 More sharing options...
about2flip Posted December 22, 2008 Author Share Posted December 22, 2008 I used the UNION statement but it is placing the soups and salads in the same table and I need it to show up in another table. Any Help is greatly appreciated. Link to comment https://forums.phpfreaks.com/topic/138031-question-about-multiple-sql-queries/#findComment-721421 Share on other sites More sharing options...
Mad Mick Posted December 22, 2008 Share Posted December 22, 2008 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. Link to comment https://forums.phpfreaks.com/topic/138031-question-about-multiple-sql-queries/#findComment-721434 Share on other sites More sharing options...
about2flip Posted December 22, 2008 Author Share Posted December 22, 2008 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); ?> Link to comment https://forums.phpfreaks.com/topic/138031-question-about-multiple-sql-queries/#findComment-721443 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.