douniani679741 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: http://www.mybringback.com/android-sdk/13193/android-mysql-php-json-part-5-developing-the-android-application/ http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/

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

  • 写回答

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):

    <?php
    //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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题
  • ¥15 Utunbu中vscode下cern root工作台中写的程序root的头文件无法包含
  • ¥15 麒麟V10桌面版SP1如何配置bonding