Jump to content


Mulktiple checkboxes, arrays

  • Please log in to reply
2 replies to this topic

#1 jwwceo

  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 28 August 2006 - 06:32 PM

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...

#2 shocker-z

  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 28 August 2006 - 06:37 PM

Hi again..
What you could do is delete all rows already in DB then loop the array to insert all checked in

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

that will dleete them all

then use

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

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

www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 jwwceo

  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 28 August 2006 - 06:43 PM

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!!!



0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users