too long

I have 10 rows, however when I do the following, it's only giving me the last row. Any kind of help I can get on this is great appreciated!

$query = "select * FROM `$table`.`channels` WHERE `country`='vietnam' ORDER BY `chanid`"; 
  $result = mysql_query($query,$db) or die(mysql_error());
  $data = array();
  while($row = mysql_fetch_array($result)) {
      $chanid = $row['chanid'];

        $data[navtitle] = "$chanid - $row[title]";
        $data[navurl] = "http://www.localhost.com/vietnam.php?chanid=$row[chanid]&country=$row[country]";
        $data[vid_art] = "$chanart";

  }

$array2=array_merge(array($array,array($data));

$JSON=json_encode($array2);

echo $JSON;

My $data array is only outputs the last row of my mysql fetch. How can I get it to pull out all 10 rows that I have?

Each time you go through the

while($row = mysql_fetch_array($result)) {

loop, you're setting $data to a new value.

This means it'll only ever contain the last row's worth of data.

Your code should look something like this.

$array2 = array();
while ($row = mysql_fetch_array($result)) {
    $data = array();
    $chanid = $row['chanid'];

    $data['navtitle'] = "$chanid - $row[title]";
    $data['navurl'] = "http://www.localhost.com/vietnam.php?chanid=$row[chanid]&country=$row[country]";
    $data['vid_art'] = $chanart;

    $array2[] = $data;
}

$JSON = json_encode($array2);