Having trouble with while

Hi guys,
With the first $get query, I’m trying to present the user with all members from a certain age group. But inside that query I want to add all countries that specific member wants to see by using the $getCountry query.
The problem is the information echoeing out under “all countries I want to see”.
Let’s say I have Adam wanting to see USA and Ecuador. Ben wants Mexico and Tom England. The information will come out as:

  1. Name:Adam
    SOA: Urgent
    all countries I want to see: USA, Ecuador

  2. Name:Ben
    SOA: Urgent
    all countries I want to see: USA, Ecuador, Mexico

  3. Name:Tom
    SOA: Urgent
    all countries I want to see: USA, Ecuador, Mexico, England.

Why is it doing that. I tried playing around with the while loop but nothing. All I want it to do is present each member with his countries.


$get = mysql_query("SELECT * FROM mainweb WHERE age='$age_form' AND who='civilian'");

while ($row = mysql_fetch_assoc($get))
{

$username= $row['username'];

$soa= $row['soa'];

echo"<p><span style='color: rgb(51, 102, 255);'>SOA</span>: $soa<p />";

echo"<p><span style='color: rgb(51, 102, 255);'>all countries I want to see</span>:";
$getCountry = mysql_query("SELECT country FROM mainweb WHERE username='$username' AND who='civilian'");
while ($row = mysql_fetch_array($getCountry)) {
    $cwb_countires[] = $row['country'];
}
     foreach ($cwb_countires as $country)
      echo " $country,";

<hr size='1'><p>";
}

You don’t initialize the countries array before the second while loop, so it’ll just add the countries to the ones already present (= the ones from the previous members).

But I can’t I thought.
I initializing the countries array from within the $row = mysql_fetch_array. How can I initialize the array without fetching it as an array first?


$get = mysql_query("
  SELECT * 
  FROM mainweb 
  WHERE age='$age_form' 
  AND who='civilian'
");
while ($row = mysql_fetch_assoc($get)) {
  $username= $row['username'];
  $soa= $row['soa'];
  echo"<p><span style='color: rgb(51, 102, 255);'>SOA</span>: $soa<p />";
  echo"<p><span style='color: rgb(51, 102, 255);'>all countries I want to see</span>:";
  $getCountry = mysql_query("
    SELECT country 
    FROM mainweb 
    WHERE username='$username' 
    AND who='civilian'
  ");

[B][COLOR="Red"]  // initialize the array before entering the while loop
  $cwb_countires= array();[/COLOR][/B]  

  while ($row = mysql_fetch_array($getCountry)) {
    $cwb_countires[] = $row['country'];
  }     
  foreach ($cwb_countires as $country) echo " $country,";
  <hr size='1'><p>";
}  

It worked Guido thanks.
But why is that if I don’t initialize the countries array before the second while loop, it just adds the countries to the ones already present?
I mean, theoretically why do I have to declare $cwb_countires as an array before the loop starts?

Because if you don’t tell the parser to empty the array for each member, it just adds new elements to the array.