forumnz Posted February 1, 2008 Share Posted February 1, 2008 I have 2 queries that need to run. One gets the Names of something, and the second gets the sub-names from a separate table to be displayed under each name respectively. I am running the second query within the first one while { }. Is this right? At the moment, it is just displaying one name and one set of sub-names, instead of multiple names/sub-names. Here is my code: <?php include('connectdb.php'); $id = $_GET['id']; $sql ="SELECT * FROM `menu_headers` WHERE `menuhid`='$id'"; $result = mysql_query($sql) or die(mysql_error()); $numr = mysql_num_rows($result); while($row = mysql_fetch_array($result)) { $name = $row['name']; $headid = $row['id']; echo "$name<br />"; $sql ="SELECT * FROM `menu_items` WHERE `menuid`='$headid'"; $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($result)) { $name = $row['name']; echo $name . "<br />"; } } ?> What could be wrong? Thanks, Sam. Quote Link to comment https://forums.phpfreaks.com/topic/88971-running-to-db-queries-in-one-go/ Share on other sites More sharing options...
trq Posted February 1, 2008 Share Posted February 1, 2008 Look closer at your logic. In the first while you create an array called $row, then within that while you obveride it with another variable called $row. Quote Link to comment https://forums.phpfreaks.com/topic/88971-running-to-db-queries-in-one-go/#findComment-455687 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.