Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    checkboxes (checked or not) and MySql - update multiple rows

    Hi,

    I am having problems with checkboxes (checked or not) and MySql - update multiple rows.

    My aim is to have a user update multiple records based on the status of the checkbox.

    The story so far...

    I am using a do-while loop to generate a list of 'items' from my db.
    Each 'item' has a checkbox next to it, with a value of item_id.

    The database has a 'published' field (enum 'y','n'). When published='y' the item will appear on the site and conversely published='n' wont.

    When the form is submitted the checkboxes make up the published[] array.

    This is where I need to update each record in the database with either a 'y' or a 'n'.

    It seems that by default checkboxes are not included in the $_POST superglobal unless they are checked, I need all the items in my array, checked or not, in order to update the db.

    Hope that makes sense - its been a long day...

    Thanks

  • #2
    New Coder
    Join Date
    Aug 2007
    Posts
    16
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I have just had a similar problem resolved using the following query.

    PHP Code:
    $query 'UPDATE yourtable SET yourfieldf= NOW() where ops_id IN (' implode(','$_POST['checkbox']) . ')'
    In my case I only wanted those boxes that were checked to update but I would assume (provided you have set a value for the checkbox) that the above query would work in your case.

    No guarantee but this code saved me several days of heartache.

    JBLC

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    You could try building an array of the items, then looping through the changes & updating the array simultaneously, and finally updating the database with the changes.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •