Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Headers and Lists

Status
Not open for further replies.

NigeB

Technical User
Nov 29, 2000
53
GB
I am trying to create a page that queries a table containing team names and country to return a list thus

Belgium
Smiths Team
Jones Team
Rogers Team

Holland
Sithy's Team
Peters Team

etc etc,

I have written a query, but unfortunatly it only returns the first country and teams from that country, any pointers as to the errors greatly appreciated -

Nigel

Code -------

$query1 = "SELECT DISTINCT country FROM teams_online";
$result1 = mysql_query($query1);
while ($row = mysql_fetch_array($result1)) {

$region = $row"country";
$query2 = "SELECT * from teams_online where country ='$region' order by team_name";
$result2 = mysql_query($query2);
}

mysql_free_result($result1);

if ($myrow = mysql_fetch_array($result2)){

echo &quot;<table width=600 border=0><tr><td>'$region'</td></tr>\n&quot;;

$i =1;

do{

printf(&quot;<tr><td>%s</td><td>%s</td></tr>\n&quot;, $i, $myrow&quot;team_name&quot;);

$i++;

} while ($myrow = mysql_fetch_array($result2));


echo &quot;</table>\n&quot;;

} else {

echo &quot;Sorry, no Team records were found!&quot;;

}
 
Your looping constructs are not nested correctly.

As I understand your script, you query for countries, then using each country in turn query for teams.

You'll have to nest like this:

Code:
//start table tag
$query = <query for countries>;
$res1 = mysql_query ($query);
while ($c_row = mysql_fetch_assoc($res1))
{
   //output country name in appropriate <tr> and <td> tags here

   $query = <select teams in a country>;
   $res2 = mysql_query();
   if (mysql_num_rows($res2) > 0)
   {
      while ($t_row = mysql_fetch_assoc($res2))
      {
         //output team name in appropriate tags
      }
   }
   else
   {
      //output &quot;no teams&quot;
   }
}

Want the best answers? Ask the best questions: TANSTAAFL!!
 
sleipnir214,

thank you for the correction, it worked a treat.

Regards

Nige B
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top