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 NT4.0系统 STOP:0X0000007B
  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。