This is my php code:
$query = Select * from tablename;
$result = mysql_query($query) or die((mysql_error()));
$count = 0;
if (mysql_num_rows($result) > 0){
while( $row = mysql_fetch_array($result)){
$json_output[$count]=$row;
$count ++;
}
}
$output = json_encode($json_output);
$output = str_replace('[{', '{', $output);
$output = str_replace('}]', '}', $output);
echo $output;
And this is a part of my php output:
{"0":{"0":"2","Gi_Id":"2","1":"sample_name.jpg","Gi_nome_file":"sample_name.jpg","2":"sample_name","Gi_Pseudonimo":"s. name","3":"sample name","
as you can see, there are the tag "0", "1" , "2", etc that represent the column number ( "0" for Gi_Id , "1" for Gi_nome_file etc) of my sql table. Why there are this duplicates? Probally i can manage this output ignoring the duplicate single cell value, but i want to undestand how to fix that.
I think that the problem is this row of my code:
$json_output[$count]=$row;
but i don't find another way to get all my table data.
Any suggestions?
EDIT
Using mysql_fetch_assoc i dont have the duplicate but remains the number at the begining of each row, my output is the following:
{"0":{"Gi_Id":"2","Gi_nome_file":"sample_name.jpg","Gi_Pseudonimo":"s. name",
and for the row number 2 i have:
{"1":{"Gi_Id":"3","Gi_nome_file":"sample_name.jpg","Gi_Pseudonimo":"s. name",
and for the row number 3 i have:
{"2":{"Gi_Id":"4","Gi_nome_file":"sample_name.jpg","Gi_Pseudonimo":"s. name",
...
and for the row number n i have:
{"n":{"Gi_Id":"n+1","Gi_nome_file":"sample_name.jpg","Gi_Pseudonimo":"s. name",
etc i would like to remove the {"0": , {"1": ,{"2":, {"3": at the begining of each row , how i can do this?