Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9007797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:47:08+00:00 2026-06-16T01:47:08+00:00

I need to pass data from MYSQL database to android application by creating JSON

  • 0

I need to pass data from MYSQL database to android application by creating JSON object. I am able to pass only the first value from MYSQL database. How to pass all the values together to android application. (My database contains Latitude and Longitude values of more than 10 locations.)

Following is my code for passing only the first row value from database to android app.

        try {

        HttpClient client = new DefaultHttpClient();
        URI website = new URI("http://192.168.1.15/latlonret1.php");
        HttpGet request = new HttpGet();
        request.setURI(website);
        HttpResponse response = client.execute(request);
        in = new BufferedReader(new InputStreamReader(response
                .getEntity().getContent()));
        StringBuffer sb = new StringBuffer("");
        String l = "";
        String nl = System.getProperty("line.separator");

        while ((l = in.readLine()) != null) {
            sb.append(l + nl);
        }
        in.close();
        data = sb.toString();
        // return data;
    } catch (Exception e) {
        Log.e("log_tag", "Error converting result " + e.toString());
    }
        try {
        String returnString;
        String returnString1;
        JSONArray jArray = new JSONArray(data);
        for (int i = 0; i < jArray.length(); i++) {
            JSONObject json_data = jArray.getJSONObject(i);
            JSONObject json_data1 = jArray.getJSONObject(i);


            returnString=json_data.getString("lat") + "\n";
            returnString1=json_data1.getString("lon") + "\n";
            System.out.println(returnString);
            System.out.println(returnString1);

            Intent viewIntent =new Intent(Androidmap.this,Mapview.class);

            Bundle bundle = new Bundle();
            bundle.putString("stuff", returnString); 
            viewIntent.putExtras(bundle);

            Bundle bundle1 = new Bundle();
            bundle1.putString("stuff1", returnString1); 
            viewIntent.putExtras(bundle1); 
            startActivity(viewIntent);
      }

This is my Server side coding :

<?php
 ob_start();
 $host="localhost"; // Host name 
 $username=""; // Mysql username 
 $password=""; // Mysql password 
 $db_name="test"; // Database name 
 $tbl_name="manu"; // Table name 

 mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
 mysql_select_db("$db_name")or die("cannot select DB");
 $sql = "select lat , lon from manu ";
 $result=mysql_query($sql);

 if(! $result )
 {
 die('Could not get data: ' . mysql_error());
 }

 while($row=mysql_fetch_array($result , MYSQL_ASSOC)) 
{

$output[]=$row;

}

 echo json_encode($output);
 mysql_close();
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T01:47:09+00:00Added an answer on June 16, 2026 at 1:47 am

    you will need to append next lat and lon value in previous string as:

    ArrayList<String> arrlan=new ArrayList<String>();
    ArrayList<String> arrlat=new ArrayList<String>(); 
           for (int i = 0; i < jArray.length(); i++) {
                JSONObject json_data = jArray.getJSONObject(i);
                JSONObject json_data1 = jArray.getJSONObject(i);
    
    
                returnString  =json_data.getString("lat") + "\n";
                returnString1  =json_data1.getString("lon") + "\n";
    
                arrlat.add(returnString);  
                arrlan.add(returnString1);   
    
                System.out.println(returnString);
                System.out.println(returnString1);
          }
     Intent viewIntent =new Intent(Androidmap.this,Mapview.class);
    
    
     viewIntent.putStringArrayListExtra("returnString",arrlat);
     viewIntent.putStringArrayListExtra("returnString1",arrlan);
    
    
     startActivity(viewIntent);
    

    and in Mapview get these arraylist as:

    ArrayList<String> arrlan=new ArrayList<String>();
    ArrayList<String> arrlat=new ArrayList<String>(); 
    
    arrlat = getIntent().getStringArrayListExtra("returnString");
    arrlan = getIntent().getStringArrayListExtra("returnString1");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to get some data from a mysql database.I'm running a php script
I have a server script that I need to pass data to from the
I'm writing a web application where I need to pass some user data to
I need to pass a complex object representing a data filter to an action
I need to be able to pass HTML data into Outlook like this: MailMessage
From my c# code behind, i pass a query to mysql database and get
I need a fastest solution for transferring data from XML file to MySQL tables.
I need to import data from a file into a Microsoft SQL Server database.
I have s MySQL database and I need to insert some specific data in
I need help in understanding the right way to pass an object (MySQL connection)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.