mysql - Php mysql_fetch add me the row number at the begining of each row -


this php code:

 $query = select * 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 part of 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 can see, there tag "0", "1" , "2", etc represent column number ( "0" gi_id , "1" gi_nome_file etc) of sql table. why there duplicates? probally can manage output ignoring duplicate single cell value, want undestand how fix that.

i think problem row of code:

 $json_output[$count]=$row; 

but don't find way table data.

any suggestions?

edit

using mysql_fetch_assoc dont have duplicate remains number @ begining of each row, output following:

{"0":{"gi_id":"2","gi_nome_file":"sample_name.jpg","gi_pseudonimo":"s. name",  

and row number 2 have:

{"1":{"gi_id":"3","gi_nome_file":"sample_name.jpg","gi_pseudonimo":"s. name",  

and row number 3 have:

{"2":{"gi_id":"4","gi_nome_file":"sample_name.jpg","gi_pseudonimo":"s. name",  

...

and row number n have:

{"n":{"gi_id":"n+1","gi_nome_file":"sample_name.jpg","gi_pseudonimo":"s. name",  

etc remove {"0": , {"1": ,{"2":, {"3": @ begining of each row , how can this?

i solve problem:

this solution:

 $result = mysql_query($query) or die((mysql_error())); 

$json_output = array(); $count = 0;

$response["prova"] = array(); if (mysql_num_rows($result) > 0){

while( $row = mysql_fetch_assoc($result)){       $json_output[$count]=$row;      // push single rating final response array       $count ++;  }  array_push($response["prova"], $json_output);   }  //alla fine aggiungo il tag di successo $json_output["success"] = 1;  $output = json_encode(array($response)); //rimuovo le parentesi graffe per far si che non mi dia problemi con il json di android $output = str_replace('[{', '{', $output); $output = str_replace('}]', '}', $output);  echo $output; 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -