The problem is that I get only the last value comming from the Table. I think its because I am building the array while referencing its values to the same object, and it keeps c
I'd go with something like:
$namesArray=array();
while($row=mysql_fetch_array($result)){
$nameAndCode=array("code"=>$row["country_code2"],
"name" => $row["country_name"]);
array_push(&$namesArray,$nameAndCode);
};
I'd also try passing $namesArray
by reference, like Viktor mentioned.
My code makes completely new array to push each iteration, which makes sure you dpn't overwrite stuff. Also, if you want to add stuff to an array by accessing it via its index you should use this:
// This is the right way
$someArray["foo"]="bar";
$someArray["baz"]="quux";
// This is wrong, it's only for OOP
$someArray->foo="bar";
$someArray->baz="quux";