Ask a Question related to PHP Development, Design and Development.
-
Adrian Parker #1
Handle Multiple Check Boxes?
I have a PHP generated page which displays X many records. Each record has
a checkbox preceding it. The user checks several checkboxes, and hits a
delete button. All the corresponding records will be deleted.
But I'm running into difficulty...
Right now the NAME property of each check box is the primary key of the
corresponding record. Hence if I know which checkboxes are checked, I
simply use DELETE using the NAME value.
Generally speaking, how do I get the server side to see which check boxes
were checked?
The check box names may not be sequential, if any records have been deleted
previously, and the first check box might be a number greater than 0.
Is there an easy mechanism to do this? Some kind of built in cnotrol array
allowing me to loop over every check box that was on the form submitted?
I could store the last and first checkbox number in a hidden input, then
loop starting/ending at those values, but that may loop over a lot of
controls that do not exist.
Thoughts?
<Ade
--
Adrian Parker. Ordained priest. <adrian.parker@sympatico.ca>
"A society that views graphic violence as entertainment ...should not be
surprised when senseless violence shatters the dreams of it's youngest and
brightest..." - Ensign (March 2004)
Adrian Parker Guest
-
Inserting Check Boxes
I NEED HELP! PLEASE! Ill explain best I can.. here is what I got: I need to use check boxes so a user can select/deselect the ingrediants they... -
CFMail & Check Boxes
I'm sure this question has been asked and answered before but I couldn't find it the forum. Sorry about that. I'm looking for a work around to the... -
Check Boxes
Fmpro 5.5 Windows XP pro I have a number field set up as a checkboxes, numbered from 11 to 18. I had a script that used to check all the boxes... -
P. S. re check boxes
I can only export this in a filtered web page. That's the only option I am given. If these alignment problems are due to that aspect, how do I... -
Check to see if Check Boxes are Checked
How do I check to see if a checked box is check on the following page? This is what I have. What am I doing wrong? <%If... -
Milambar #2
Re: Handle Multiple Check Boxes?
Adrian Parker wrote:
generate the list with something like this:> I have a PHP generated page which displays X many records. Each record has
> a checkbox preceding it. The user checks several checkboxes, and hits a
> delete button. All the corresponding records will be deleted.
>
> But I'm running into difficulty...
>
>
> Right now the NAME property of each check box is the primary key of the
> corresponding record. Hence if I know which checkboxes are checked, I
> simply use DELETE using the NAME value.
>
> Generally speaking, how do I get the server side to see which check boxes
> were checked?
>
> The check box names may not be sequential, if any records have been deleted
> previously, and the first check box might be a number greater than 0.
>
> Is there an easy mechanism to do this? Some kind of built in cnotrol array
> allowing me to loop over every check box that was on the form submitted?
>
> I could store the last and first checkbox number in a hidden input, then
> loop starting/ending at those values, but that may loop over a lot of
> controls that do not exist.
>
>
> Thoughts?
>
>
>
> <Ade
$result = mysql_query("SELECT * FROM table", $fh);
while ($row = mysql_fetch_array($result)) {
echo "<input name="id[]" type="check value="$row[0]"><br>";
}
then when it gets passed to the serverside, $_POST['id'] will be an
array containing the values of the checked boxes. Just walk through the
array deleting them one by one.
Off the top if my head without testing:
$delete = $_POST['id'];
foreach ($delete as $this) {
mysql_query("delete from table where id=$this");
}
I hope this helps, and btw, it took me a while to understand how
checkboxes were handled too.
Milambar Guest
-
Milambar #3
Re: Handle Multiple Check Boxes?
Milambar wrote:
Meh, dont forget to escape the quotes in the generation part:> Adrian Parker wrote:
>>>> I have a PHP generated page which displays X many records. Each
>> record has
>> a checkbox preceding it. The user checks several checkboxes, and hits a
>> delete button. All the corresponding records will be deleted.
>>
>> But I'm running into difficulty...
>>
>>
>> Right now the NAME property of each check box is the primary key of the
>> corresponding record. Hence if I know which checkboxes are checked, I
>> simply use DELETE using the NAME value.
>>
>> Generally speaking, how do I get the server side to see which check boxes
>> were checked?
>>
>> The check box names may not be sequential, if any records have been
>> deleted
>> previously, and the first check box might be a number greater than 0.
>>
>> Is there an easy mechanism to do this? Some kind of built in cnotrol
>> array
>> allowing me to loop over every check box that was on the form submitted?
>>
>> I could store the last and first checkbox number in a hidden input, then
>> loop starting/ending at those values, but that may loop over a lot of
>> controls that do not exist.
>>
>>
>> Thoughts?
>>
>>
>>
>> <Ade
> generate the list with something like this:
>
> $result = mysql_query("SELECT * FROM table", $fh);
> while ($row = mysql_fetch_array($result)) {
> echo "<input name="id[]" type="check value="$row[0]"><br>";
> }
>
> then when it gets passed to the serverside, $_POST['id'] will be an
> array containing the values of the checked boxes. Just walk through the
> array deleting them one by one.
>
> Off the top if my head without testing:
>
> $delete = $_POST['id'];
> foreach ($delete as $this) {
> mysql_query("delete from table where id=$this");
> }
>
> I hope this helps, and btw, it took me a while to understand how
> checkboxes were handled too.
echo "<input name=\"id[]\" type=\"checkbox\" value=\"$row[0]\"><br>";
Sorry. But it is 3am here at the moment.
Milambar Guest



Reply With Quote

