I want to get json with php encode function like the following
Just change that lines
echo json_encode(array('id'=>$i, 'name' => $row['name'])); echo ",";
To these
echo ","; echo json_encode(array('id'=>$i, 'name' => $row['name']));