dimanche 9 février 2020

How to insert multiple set of checkboxes with different names in different table column

I have 3 set of checkboxes in my form and I designed it in such a way that if one is checked, the 3 checkboxes for a particular product will be checked. Which means on submission, the 3 set of checkboxes (itemQuantities[],itemIds[] and sectionIds[]), when I convert them to array using

$item_quantities              = $_POST['itemQuantities'];
$item_ids                     = $_POST['itemIds'];
$section_ids                  = $_POST['sectionIds'];

They 3 arrays must contain the same number of elements. How can I insert the values of these arrays in one table with one element of the first array into one column, the first element of the second array into the next column, the first element of the third array into the third column and like that.... The number of rows will be the number of elements in one array (Since all arrays have equal elements). For instance:

$array1 = array(1,2,3);
$array2 = array(4,5,6);
$array3 = array(7,8,9);

In the database, I want to have:

| col1 | col2 | col3 |
----------------------
|   1  |   4  |   7  |
|   2  |   5  |   8  |
|   3  |   6  |   9  |

How can I achieve this. I have tried using nested foreach loop but it's not working. Any help will be appreciated. Thanks




Aucun commentaire:

Enregistrer un commentaire