Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-21-2007, 05:42 PM   PM User | #1
concretegong
New to the CF scene

 
Join Date: May 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
concretegong is an unknown quantity at this point
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
concretegong is offline   Reply With Quote
Old 08-21-2007, 08:09 PM   PM User | #2
JBLC
New Coder

 
Join Date: Aug 2007
Posts: 16
Thanks: 3
Thanked 0 Times in 0 Posts
JBLC is an unknown quantity at this point
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
JBLC is offline   Reply With Quote
Old 08-21-2007, 08:13 PM   PM User | #3
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,602
Thanks: 2
Thanked 398 Times in 391 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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.
Inigoesdr is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:42 PM.


Advertisement
Log in to turn off these ads.