Jump to content

Archived

This topic is now archived and is closed to further replies.

jwwceo

Mulktiple checkboxes, arrays

Recommended Posts

So I finally got my checkboxes working to where I can add them to a databse, and have the correct checkboxes already "checked" on the edit page when a user comes in the make changes...

however, what kind of query do I use to update any changes in the checkboxes...there might be as many as 50 boxes...

say theres 20 boxes currently checked and the user checks 10 more....an UPDATE query only updates current rows...in this case I'd need to update 20 and add 10....plus all the rows will have the same shirt_id since all the checkboxes relate to the same product....

does this make sense...

Share this post


Link to post
Share on other sites
Hi again..
What you could do is delete all rows already in DB then loop the array to insert all checked in


[code]mysql_query("DELETE * FROM tablename WHERE shirt_id = '$shirt_id'") or die (mysql_query());[/code]

that will dleete them all

then use

[code]foreach ($_POST['checkbox'] as $checkbox) {
mysql_query("INSERT INTO table_name (shirt_id, color) VALUES('$shirt_id','$color')") or die (mysql_query());
}[/code]

I based the code on you still talking about the shirts and colors site

Liam

Share this post


Link to post
Share on other sites
Thank you Liam! You have been very helpful on this part of my project...arrays are still a little confusing and I don't know that many commands to work with them...you've shown me some cool things!!!

thanks!

James

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.