How To Update Multiple Rows In One Query
RegisterLogin
How To Update Multiple Rows In One Query
Post Description: Have You Seen Websiste That Have Multiple Checkboxes In Their Forms And Select Which Choices You Want And To Ignore The Rest
Tags: How, To, Update, Multiple, Row, In, One, Query
This Post Was Posted On Feb 16, 2010 By Webune Support #3143
Post Description: Have You Seen Websiste That Have Multiple Checkboxes In Their Forms And Select Which Choices You Want And To Ignore The Rest
Tags: How, To, Update, Multiple, Row, In, One, Query
This Post Was Posted On Feb 16, 2010 By Webune Support #3143
How To Update Multiple Rows In One Query by Webune Support
have you seen websiste that have multiple checkboxes in their forms and select which choices you want and to ignore the rest
for example, lets say i have a form that looks like this:
please choose your favorite color:
Red
Blue
Green
Yellow
Orange
Black
as you can see from my form, you can choose which colors you like and i want to have a mysql query where only the boxes that are checked i want to update and ignore that ones that are not checked.
its easy, you have to give the name of the input to an array, for example like this:
<input type="checkbox" name="colors[]" value="1"> Red
so this will create an array and all i have to do is update the ones that have values in the array. so my array would look like if i select Red and Blue only: OUTPUT
[colors] => Array
(
[0] => Red
[1] => Blue
)
once you have submited you can use a loop to put it all together:
PHP CODE:
for($counter =0; $counter < count($_POST['colors']); $counter++) {
if(!$Selected) $Selected = $_POST['colors'][$counter];
else $Selected .= ','.$_POST['colors'][$counter];
}
the query would look like this:
$Query = "UPDATE MyColors SET colors='active' WHERE ColorChoices in ('".$Selected."');
if you want to see the complete script, download from this post in the attachments below
Download File: CheckBox_Array.zip
Leave Your Comments
mevlin
#3756 1
how do you update many rows in same query
Apr 10, 2010 Reply Report abuse
©2011 Webune Forums - Sun Dec 18, 2011 3:16 pm
Powered by: Webune Forums V3
Powered by: Webune Forums V3