2015-05-26 17:47
浏览 83

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

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

图片转代码服务由CSDN问答提供 功能建议

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

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

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

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

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

  • dongqiang4986 2015-05-26 18:46

    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

    解决 无用
    打赏 举报

相关推荐 更多相似问题