Could I get some quick guidance on inserting multiple rows - CF to (MySQL)?
My question is whether there's a simpler way to do the following than what I've discovered on my own.
My user will run a query and make selections of items (MID) from a table. These MIDs will be stored in another table along with the user's UserID. This will allow the user to tailor another query to be populated only with these MIDs. The user might make one set of selections and then replace it later with a different set of selections.
Right now, I'm not worrying about how to code the CFML to produce the query I send to MySQL. I'm just wanting to know if this is a suitable/optimal method of doing it.
tbl_user_units has three columns, UUID (autoincrement), UserID, MID.
I'm using 202 for the UserID in this example
The user is likely to select between 20 and 40 MIDs
I would use a form with checkboxes to select the MIDs
Not knowing how to delete old selections and insert new ones in a single operation, I propose to first delete all the old values using this:
DELETE from tbl_user_units
WHERE userid = 202;
Then, insert the newly selected MIDs (for example, 224, 225, 226):
INSERT INTO tbl_user_units (userid,mid)
VALUES
(202,224),
(202,225),
(202,226),
;
I could store the selections in a single field in the tbl_user table as a list, e.g., Units = [224,225,226]. I'm inexperienced with lists and arrays. Would it be simpler to read the list from this field and use it to create my query? This would obviate the need for a separate table.
Thanks for your feedback!
John
