0

Suppose I have the following table in a mysql database of my app:

TABLE MANAGER

enter image description here

Now I want to add this checkbox option in android.
enter image description here

And based on the selections I would want to run query in my database.
For example if the user selected NY and NJ, I would run the following query:

SELECT * FROM MANAGER WHERE city = 'NY' OR city = 'NJ'  

Again, if the user had selected NY, NJ, LA
Then I would have run the query as

SELECT * FROM MANAGER WHERE city = 'NY' OR city = 'NJ' OR city = 'LA'  

How do I make my app choose that by the number of options selected?
I am pretty novice in android, so it would be really a lot of help if someone told me this, or gave me a hint on where to learn this from :)

Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127

1 Answers1

0
//Simple Code Snippet Just To Show how this can be done their are many ways but this is less complex
    //Just Pass the selected city array
    public String makeStatement(String arg[])
    {

     String basic_statment="SELECT * FROM MANAGER WHERE";
     StringBuilder sb=new StringBuilder();
     sb.append(basic_statment);

     for(int i=0;i<arg.length;i++)
     {
        sb.append(" city = ");
        sb.append("'"+arg[i]+"' ");
        if(i!=arg.length-1)
        sb.append("OR");

     }

     return sb.toString();
    }

Try This

Rachit Solanki
  • 369
  • 6
  • 13