Skip to content Skip to sidebar Skip to footer

How To Insert Selected Multiple Checkbox Values Into Different Rows To Mysql Database In Android And Php

Here i am accessing contacts from the phone and displaying in custom listview. Now i have to insert the selected checkbox values to different rows to mysql database.Here i can able

Solution 1:

You need to start using JSON to hold your data:

Build it:

JSONArray contacts = newJSONArray();
for(int i = 0; i < name1.size(); i++)
{
    JSONObject contact = newJSONObject();
    contact.put(kname, name1.get(i).toString());
    contact.put(kphone, phno1.get(i).toString());
    contact.put(kvault,vault_no);
    contacts.put(contact);
}

Then pass it to your hashmap as a parameter:

HashMap<String,String> param = newHashMap<String,String>();
param.put(kcontacts,contacts.toString());
return rh.sendPostRequest(UPLOAD_URL, param);

Finally in PHP decode that:

$contacts = json_decode($_POST['contacts'], true);
foreach($contactsas$contact){
    echo$contact['name'];
}

Solution 2:

use Foreah post of check box values.

$vault_no1= $this->input->post("vault_no");
       foreach($vault_no1as$key=>$val){
            $arra[] = $val;
        }


        $name= $this->input->post("name");
       foreach($nameas$key=>$val){
            $arre[] = $val;
        }


        $phone= $this->input->post("phone");
       foreach($phoneas$key=>$val){
            $arrv[] = $val;
        }

        $length = count($arra);
        for ($i = 0; $i < $length; $i++) {
          echo"vault_no".$arra[$i]." Name:".$arre[$i]." phone:".$arrv[$i];   //Sample print for you//Use your Insert query here with aboe arrays value
        }

Post a Comment for "How To Insert Selected Multiple Checkbox Values Into Different Rows To Mysql Database In Android And Php"