how is it possible to output my rows into a checkbox group and insert them into a database at based on the ID of the items checked?
So user checks 1,2,3,4,5 and I insert the ID of 1,2,3,4,5 into myTable.
I’ve only ever dealt with 1 x $myVariable INSERTS so far..
MySQL has an extended insert syntax. Assuming your checkbox values are stored in a normalized table, you’d use something like
which would produce a new record in
yourtablefor each value you specify. Note that you can insert sets of values in the same manner:You’d have to build up that list of values yourself, as the brackets around them are required for the extended insert to work. You can’t simply do
INSERT .... implode($_POST['checkboxes']type of thing.Now, if you want to insert a comma-separated list of IDs into a single field/record in the DB, then I strongly suggest you don’t. Normalize your database and create a sub-table for those values.