i am trying to import Mysql column in andorid column here is my php file which getting column values it showing me all records
like this
[{"nome":"A BARATEIRA DE TECIDOS LIMITADA ME"}][{"nome":"A BARATEIRA DE TECIDOS LIMITADA ME"},{"nome":"A.A.L. COMESTIVEIS E RESTAURANTE LTDA ME"}][{"nome":"A BARATEIRA DE TECIDOS LIMITADA ME"},{"nome":"A.A.L. COMESTIVEIS E RESTAURANTE LTDA ME"},{"nome":"ACOUGUE E MERCEARIA COSTELAO DA SERRA LTDA ME"}]"
//my php file
<?php
mysql_connect("localhost","root","abcd");
mysql_select_db("fabricacao");
$sql=mysql_query("SELECT nome FROM cliente ORDER BY NOME") ;
$nome ='nome';
while($rows=mysql_fetch_assoc($sql))
{
$output[]=$rows;
print(json_encode($output));
mysql_close();
}
?>
my problem is here when i am converting records of result into Array then JSONArray.lenght() showing ‘size =1’ and inseting just first one record, i dont understand where is problem i want store all rows ?
try
{
JSONArray jArray = new JSONArray(result);
//mydb
sql= openOrCreateDatabase("CLT",SQLiteDatabase.CREATE_IF_NECESSARY,null);
ContentValues values=new ContentValues();
int n = jArray.length();
for(int i=0;i<jArray.length();i++)
{
JSONObject json_data = jArray.getJSONObject(i);
values.put("CLIENT", json_data.getString("nome"));
sql.insert("clnt", null, values);
}
sql.close();
}catch(Exception e)
{
Log.e("Erro",e.toString());
}
add your result data into arraylist and then add it into your db. check the below code for getting all the records coming from the database.