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 8169429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:50:47+00:00 2026-06-06T20:50:47+00:00

I’m new to Android and PHP. What I’m trying to do is retrieve the

  • 0

I’m new to Android and PHP. What I’m trying to do is retrieve the search value back to the Android device from an external MySql database. The database consists of 200,000 entries at 174MB, so including it in the package and using the internal SqlLite isn’t an option.

<?php

  mysql_connect("myhost","myuser","mypass");

  mysql_select_db("mydb");

$sql=mysql_query("select * from myTable");

$output = array();
while($row = mysql_fetch_assoc($sql)) {
$output['txt'][] = $row;
}

exit (json_encode($output));

mysql_close();
?>

In the Test class which is called from a layout, I have this.
The problem is, I can connect to the external db, even specify adding to the database, but I’m lost on getting specific user defined terms. Right now when I run it, it will try to download the entire Table (120,000 entries), parse to a String, and show to a listview, but at 10MB it crashes and must be fc. If I could figure out how to specify the PHP and Android to play nice, like when someone searches for eggs, then all values for eggs are returned (carbs, calories, mm, etc).

Since the PHP script is static, I don’t see how it is possible to change the get command, but I know it is possible because I’ve seen apps before to do it.

package carbcounter.project;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.LinearLayout;
import android.widget.TextView;


public class SqlTest extends Activity {
/** Called when the activity is first created. */

   TextView txt;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sqltest);      
    LinearLayout rootLayout = new LinearLayout(getApplicationContext());  
    txt = new TextView(getApplicationContext());  
    rootLayout.addView(txt);  
    setContentView(rootLayout);  

    txt.setText("Connecting..."); 
    txt.setText(getServerData(KEY_121)); 



}
public static final String KEY_121 = "http://android.mywebspace.com/androidscript.php";



private String getServerData(String returnString) {

   InputStream is = null;

   String result = "";
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    nameValuePairs.add(new BasicNameValuePair("Abbrev","eggs"));

    try{
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(KEY_121);
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();

    }
    catch(Exception e)
    {
            Log.e("log_tag", "Error in http connection "+e.toString());
    }

    try
    {
            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) 
            {
                    sb.append(line + "\n");
            }
            is.close();
            result=sb.toString();
    }
    catch(Exception e)
    {
            Log.e("log_tag", "Error converting result "+e.toString());
    }
    try
    {
            JSONArray jArray = new JSONArray(result);
            for(int i=0;i<jArray.length();i++){
                    JSONObject json_data = jArray.getJSONObject(i);
                    Log.i("log_tag","id: "+json_data.getInt("id")+
                            ", type: "+json_data.getString("type")+
                            ", description: "+json_data.getInt("description")+
                            ", carbs: "+json_data.getInt("carbs")
                    );
                    returnString += "\n\t" + jArray.getJSONObject(i); 
            }
    }
    catch(JSONException e)
    {
            Log.e("log_tag", "Error parsing data "+e.toString());
    }
    return returnString; 
}    

}

Thanks in advance.

p.s. I have the correct login, password, db, etc. I changed them for the post.

  • 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-06T20:50:48+00:00Added an answer on June 6, 2026 at 8:50 pm

    You’ll have to put a WHERE clause in your query.

    Catch the Abbrev parameter sent to your script from Android like this…

    <?php
        $abbrev = mysql_real_escape_string($_POST['Abbrev']);
        $query = sprintf("SELECT * FROM myTable WHERE Abbrev='%s'",$abbrev); //I assumed here that your table field is called Abbrev too
        ... your code here
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am currently running into a problem where an element is coming back from
I have a view passing on information from a database: def serve_article(request, id): served_article
I'm trying to create an if statement in PHP that prevents a single post
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text

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.