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

报告相同问题?

悬赏问题

  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?