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
Try
array_push(&$namesArray,$nameAndCode);
I think array_push requires a reference or pointer.
array_push
Is there a reason you aren't using $namesArray[]? Instead of the above:
$namesArray[]
$namesArray[] = $nameAndCode;