开发者

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
 开发者_StackOverflow中文版   <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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜