简体   繁体   中英

PHP MySQL - update multiple rows at one time

I have a form that is displaying data that is pulled from a database. There are several columns that are being pulled for the form. The basic structure of the form looks like this:

<form>
    <input type="checkbox" name="check" value="$value" checked="$valueCheck" /> $label - $editedBy @ $editedDate
    <input type="checkbox" name="check" value="$value" checked="$valueCheck" /> $label - $editedBy @ $editedDate
    <input type="checkbox" name="check" value="$value" checked="$valueCheck" /> $label - $editedBy @ $editedDate
    <input type="checkbox" name="check" value="$value" checked="$valueCheck" /> $label - $editedBy @ $editedDate
    <input type="checkbox" name="check" value="$value" checked="$valueCheck" /> $label - $editedBy @ $editedDate
    <input type="submit" name="update" value="Update Checklist" />
</form>

The variables are all populated dynamically when the pages loads from data in the database. Here is my question...each input and corresponding data is being pulled from a single row in a "checklist" table. So, in the example above you would be looking at data from 5 rows in the database. When i check off a box and click submit i want it to submit that checked box to the database as a value of true or false depending on whether or not the box is checked or unchecked. I know how to do all that if i was only submitting one row; however, i am not sure how to do this with the multiple rows. I'm assuming i'll have to use some type of loop with my UPDATE query.

What would be the best way to accomplish this? Thanks for any help! Let me know if you have any questions at all. Sorry if doesn't explain my situation well enough.

Check out this page , particularly the bits following "UPDATE ===".

Haven't tried it but apparently, you can use a CASE statement in an update query.

Should work for your case.

Sounds like a bad idea maintenance-wise though (imho)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM