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
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.