Jump to content

[SOLVED] Nested Query


Crustyfur

Recommended Posts

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
Share on other sites

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
Share on other sites

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.