3

I would like to retrieve all data for database and php file using android really I know how to retrieve single data but not all of data

$query_search = "select * from member ";
$query_exec = mysql_query($query_search) or die(mysql_error());

while($list=mysql_fetch_array($query_exec))
{
    $row[]=$list;
    echo  json_encode($row);
}
ROR
  • 271
  • 3
  • 29

2 Answers2

0

echo your json encode outside of your loop

while($list=mysql_fetch_array($query_exec))
{
    $rows[]=$list;

}
echo  json_encode($rows);
Ben Miller
  • 29
  • 7
0

Try something like this

    $your_querry="select * from member ";
    $query=mysql_query($your_querry);
               while($r = mysql_fetch_assoc($query)) {
                   $rows[] = array('data'=>$r);
               }
   echo json_encode(array('jsonresult'=>$rows));

Edit 1: poster wanted the android code:

You should call your php file to get the results and then process the json response:

    HttpClient httpclient = new DefaultHttpClient();    
    HttpPost httppost = new HttpPost("http://example.com/your_file.php");
     ResponseHandler<String> responseHandler = new BasicResponseHandler();
     String responseBody = httpclient.execute(httppost, responseHandler);
    // You dont have to use POST you can use GET...

Now your Json response is in responseBody. Next thing is parsing it to get your data

You can google many different solutions with Parsing JSON in Java or android.

here is a detailed example: How to parse JSON in Android

Community
  • 1
  • 1
JanBo
  • 2,925
  • 3
  • 23
  • 32
  • thanks I mean android code yeah you're right if have any comment for android code am really appreciate – ROR Aug 14 '13 at 19:56