Crustyfur Posted July 3, 2007 Share Posted July 3, 2007 Hi, I need the second query to display its results based on the 'townid' from the first query. I am not sure how to pass it. The page variable is '$countyid'. As you can see I have used a 'townid' of '11' as an example if I dont make any sense. <?php <table cellpadding=\"10\">"; $result = $db->sql_query("SELECT * FROM ft_clubs_town WHERE countyid = '$countyid' ORDER BY town ASC"); $counter = 0; echo "<tr><td valign=\"top\" align=\"left\">"; while($row = $db->sql_fetchrow($result)) { if($counter>25) { echo "</td><td valign=\"top\">"; $counter = 0; } echo $row["town"]; echo "<br />"; $result2 = $db->sql_query("SELECT club FROM ft_clubs WHERE townid = '11' ORDER BY club ASC"); while($row2 = $db->sql_fetchrow($result2)) { echo $row2["club"]; echo "<br />"; } echo "<br />"; $counter++; } echo "</tr>"; echo "</table> ?> Link to comment https://forums.phpfreaks.com/topic/58183-solved-nested-query/ Share on other sites More sharing options...
no_one Posted July 3, 2007 Share Posted July 3, 2007 I'll assume each row grabbed from the the first query has an id? Something like <?php $town_id = $row['id'] $result2 = $db->sql_query("SELECT club FROM ft_clubs WHERE townid = '$town_id' ORDER BY club ASC"); ?> Perhaps? Link to comment https://forums.phpfreaks.com/topic/58183-solved-nested-query/#findComment-288578 Share on other sites More sharing options...
Crustyfur Posted July 3, 2007 Author Share Posted July 3, 2007 Spot on thanks no_one. Link to comment https://forums.phpfreaks.com/topic/58183-solved-nested-query/#findComment-288593 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.