I did my first question here abour populating an array to json_encode and pass it to my javascript on client side, but what I figured out is that the problem seems to be related to json_encode and the values that come from my table. The table is filled with varchars, so it's a table with common categorys, like restaurant,shopping,etc.
I'm doing this loop to fill the array ( I had the while loop before but this one got me to understand the error)
$id=array();
for($i=0;$i<$nmr;$i++){
$row = mysql_fetch_assoc($sql);
$id[$i]=$row['Tipo'];
}
echo json_encode($id);
So, if I do it like this, my PhP page returns nothing. But if a print_r($id) it prints me the array with all the strings. If I echo $id[1]; it outputs one of the categorys, so I guess it's the json_encode no? I already set my DB to utf-8 because I noticed that json works that way, so what would be the prblem now?
Thanks
EDIT:
Forgot to mention that if I do this:
$id[0]="ola";
$id[1]="ccc";
$id[2]="sd";
json_encode($id);
output: ["ola","ccc","sd"]
it gives me the array on the output. So it only happens when I try to encode the array filled with values from my DB.
2nd Edit
I said this above but I guess it's better if I show it. The array is being populated because if I print_r($id) right after the json_encode($id) I get the populated array.
Array ( [0] => Restaurantes [1] => Cafés [2] => Shopping [3] => Eventos [4] => Hoteis [5] => Oficinas [6] => Combustiveis )