Send ArrayList from android to php MySQL

后端 未结 1 1319
挽巷
挽巷 2021-01-17 07:28

In table work_details, I have 7 column (id, project, work_description, percentage, time_in, time_out, fk). Now I want to save the arraylist

相关标签:
1条回答
  • 2021-01-17 07:51

    Your SQL query is incorrect:

    $sql="INSERT INTO work_details (project, work_description, percentage, timeIn, timeOut, id) VALUES ('$val', '$id')";
    

    You have 6 columns to set and provide only 2 values.

    Instead of iterating over $list and executing a query for each value, you should rather construct the query while iterating and execute it only once at the end when it is complete. Example:

    foreach (...) {
        $sql = $sql . "'$val', ";
        ...
    }
    $sql = "INSERT INTO work_details (project, work_description, percentage, timeIn, timeOut, id) VALUES (" . $sql . "'$id')";
    

    This is just the idea.. I'm not a PHP guy so there's probaby errors in what I wrote.

    EDIT : This assumes that order is always the same in the list.

    0 讨论(0)
提交回复
热议问题