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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:08:13+00:00 2026-06-07T14:08:13+00:00

I’m using a MySQL database and php for my java/android app. I haven’t got

  • 0

I’m using a MySQL database and php for my java/android app.
I haven’t got any experience with php.

this is my php file (getAllDataFromSomeTable.php)

<?php
mysql_connect("someHosturl","someUsername","somePassword");
mysql_select_db("databasename");

$q=mysql_query("SELECT * FROM sometable");
while($e=mysql_fetch_assoc($q))
    $output[]= $e;

print(json_encode($output));

mysql_close();
?>

and i work with HttpPosts and stuff like that in Java.
This way i can get all the data from ‘sometable’

but if i want to use a different query like “select top 1 from sometable where username = ‘thisuser'” for example. How can i change that dynamically in java?
How should my php file look and how should the code in java look?
this is the code i have now:

String result = "";
    List<? extends NameValuePair> licenses = (List<? extends NameValuePair>) new ArrayList<DriversLicense>();
    InputStream is = null;
    try{
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("http://some-url.com/getAllDataFromSomeTable.php");
        httpPost.setEntity(new UrlEncodedFormEntity(licenses));
        HttpResponse response = httpclient.execute(httpPost);
        HttpEntity entity = response.getEntity();
        is = entity.getContent();
    }catch(Exception e){
        Log.d("httpclient tag", e.getMessage());
    }

    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();
        Log.d("result is", result);
    }catch(Exception e){
         Log.d("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.d("from jsonObject", "id= " + json_data.getInt("Id") + ", number = "
                        +json_data.getString("Number"));
        }
    }catch(JSONException e){
            Log.e("log_tag", "Error parsing data "+e.toString());
    }
  • 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-07T14:08:15+00:00Added an answer on June 7, 2026 at 2:08 pm

    Why don’t you try adding parametes to the request?

    For example:

    http://some-url.com/getAllDataFromSomeTable.php?table=difftable&whereField.1=username&whereValue.1=xyz&whereField.2=surname&whereValue.2=Smith

    This way you would need to parse these parameters and build a query based on the passed data.
    I’m thinking that the above request would make this query:

    select * from difftable where username = 'xyz' and surname ='Smith'
    

    On the other hand, this is what webservices are for, so i would think about something like that, if possible.

    • 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
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I am using Paperclip to handle profile photo uploads in my app. They upload
I have a reasonable size flat file database of text documents mostly saved in
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.