android php mysql从app插入多行到数据库数据库

我的应用程序包含学生ID号码,姓名和成绩列表,我想将整个列表插入 一个数据库。 每个学生应该连续(id-name-grade,in a row)。 </ p>

我正在使用AsyncTask将我的信息发送到数据库,并想问我如何一次发送多行(每行包含多个变量)? 如果我需要将它们全部作为一个JSONObject发送,我该如何将它们分成不同的学生? </ p>

我用来创建我的应用程序的教程: -the-android-application / </ p>

我也有 发现以前的答案处理PHP方面的东西,但因为我是新来的PHP我没有真正得到它插入多个mysql行php Android </ p>
</ div>



My app holds a list of student id numbers, their names and grades, and I want to insert the entire list into a database. Each student should be in a row (id-name-grade, in one row).

I am using AsyncTask to send my info to the DB, and wanted to ask how can I send multiple rows (each one containing multiple variables)at once? If I need to send them all as one JSONObject how do I separate them back into the different students?

The tutorials I use to create my app:

I have also found previous answers that deal with the php side of things but as I am new to php I didn't really get it inserting multiple mysql rows php Android


On your server side, send the data as an array of JSON objects, then insert objects in a foreach loop, try something like this (this untested, but should get you started):

//your sample input may look something like this:
//$json_input_string = '{0:["id":123,"name":"Jon Doe","grade":"A"],1:[...]}';
$input_data = json_decode($json_input_string);
foreach($input_data->data as $item)
     //$item->id, $item->name, $item->grade all accessible here
     //insert each record here in loop


Make sure you are using using prepared statements

Ok so pesky grey rabbit answered the php side (thanks for that!), but for some reason encoding the JSONArray on the android side was not really working for me. It is probably not the neatest way to do things but I used @UncleIstvan 's answer to figure it out: INSERT multiple entries from Android -> PHP -> MYSQL

I deleted the "upload fishes" part of the json_string because (again, for some reason) it wouldn't get decoded. @UncleIstvan if I could upvote you, I would

Csdn user default icon