471,306 Members | 851 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

make array out of checkboxes?

LRW
I did a Web search, and a deja.com search on this...and I'm finding
how to make checkboxes act like radiobuttons, and other interesting
behaviors, but nothing that quite answers my question. If someone has
a link or thread they know about, even just that would be great!

What I have is a page that generates a list of items from a
database...a list of rows.
I'm having each row in the WHILE array create a checkbox, so that
someone can put checks in any row they want to delete on submitting
the form.

Now, how do I set up where it collects which checkboxes were selected?
I'm sure if I can get that far, I can figure out an EACH method of
then deleting each id from the table.

Here's what I'm doing so far with the checkboxes:
while ($row = mysql_fetch_array($result)) {
echo "<tr ".$bgcolour."><td><input name=\"del\"
type=\"checkbox\" value=\"$iid\"></td><td>" . $quantity . "</td><td>"
.. $typename . "</td><td>" . $typesize . "</td><td>$" . $amount .
"</td><td></td><td></td><td>$".round(($amount*$taxmult),2)."</td></tr>";

The $iid is the table.id mentioned in the SELECT statment before this.
So that each checkbox, when checked, will have a value of that row's
ID.

Any suggestions, even just a one-word name of the method I should look
into, would be much appreciated!

Thanks!
Liam
Jul 17 '05 #1
5 2105
I noticed that Message-ID:
<3a**************************@posting.google.com > from LRW contained the
following:
while ($row = mysql_fetch_array($result)) {
echo "<tr ".$bgcolour."><td><input name=\"del\"
type=\"checkbox\" value=\"$iid\"></td><td>" . $quantity . "</td><td>"
. $typename . "</td><td>" . $typesize . "</td><td>$" . $amount .
"</td><td></td><td></td><td>$".round(($amount*$taxmult),2)."</td></tr>";

The $iid is the table.id mentioned in the SELECT statment before this.
So that each checkbox, when checked, will have a value of that row's
ID.


The way I did this as to sequentially name the check boxes e.g.

$i=0;
while ($row = mysql_fetch_array($result)) {
echo "<tr ".$bgcolour."><td><input name=\"del$i\"
type=\"checkbox\" value=\"$iid\"></td><td>" . $quantity . "</td><td>"
.. $typename . "</td><td>" . $typesize . "</td><td>$" . $amount .
"</td><td></td><td></td><td>$".round(($amount*$taxmult),2)."</td></tr>";
$i++;
}

You know how many check boxes you have printed. When the form is
returned, do a loop to see which boxes are ticked.

for($i=0;$i<$number_of_boxes; $i++){
if(isset($_POST["del$i"])){
//do delete stuff
}
}

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #2

"LRW" <de**@celticbear.com> wrote in message
news:3a**************************@posting.google.c om...
I did a Web search, and a deja.com search on this...and I'm finding
how to make checkboxes act like radiobuttons, and other interesting
behaviors, but nothing that quite answers my question. If someone has
a link or thread they know about, even just that would be great!

What I have is a page that generates a list of items from a
database...a list of rows.
I'm having each row in the WHILE array create a checkbox, so that
someone can put checks in any row they want to delete on submitting
the form.

Now, how do I set up where it collects which checkboxes were selected?
I'm sure if I can get that far, I can figure out an EACH method of
then deleting each id from the table.

Here's what I'm doing so far with the checkboxes:
while ($row = mysql_fetch_array($result)) {
echo "<tr ".$bgcolour."><td><input name=\"del\"
type=\"checkbox\" value=\"$iid\"></td><td>" . $quantity . "</td><td>"
. $typename . "</td><td>" . $typesize . "</td><td>$" . $amount .
"</td><td></td><td></td><td>$".round(($amount*$taxmult),2)."</td></tr>";

The $iid is the table.id mentioned in the SELECT statment before this.
So that each checkbox, when checked, will have a value of that row's
ID.

Any suggestions, even just a one-word name of the method I should look
into, would be much appreciated!

Thanks!
Liam


I've always done it this way:

while ($row = mysql_fetch_array($result)) {
print "<tr><td><input type='checkbox' name='del[]' value='del'><input
type='hidden'
name='values[]'value='$id'></td><td>$quantity</td><td>$typename</td><td>$typ
esize</td><td>$."$amount".</td><td></td><td></td><td>$".round(($amount*$taxm
ult),2)."</td></tr>";
}
then when you're processing the data do something like....
for ($i = 0; $i < count($values); $i++) {
if($del[$i] = 'del') {
deleteRecord($i);
}
}

Regards,

Ian.
Jul 17 '05 #3
LRW
"Ian Taylor" <mx*@ocset.reverse.previous.word.net> wrote in message news:<40***********************@news.dial.pipex.co m>...

Actually, what I ended up figuring out was a lot easier than those:

<input name="del[]" type="checkbox" value="$iid">

Then on the PHP:

if ($del) {
foreach ($del as $v) {
$sqldel = "delete from orderscart where id = '".$v."' and
ordernum = '".$ordernum."'";
$result = @mysql_query($sqldel, $dbconn);
}
}

Works great!
Thanks for the tips to get me ther...
Liam
Jul 17 '05 #4
I noticed that Message-ID:
<3a**************************@posting.google.com > from LRW contained the
following:
if ($del) {
foreach ($del as $v) {
$sqldel = "delete from orderscart where id = '".$v."' and
ordernum = '".$ordernum."'";
$result = @mysql_query($sqldel, $dbconn);
}
}

Works great!


Yeah, the only thing I don't like about that is that it works too well.
I like to have an intermediate screen asking me if I'm sure I want to
delete these records.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #5
LRW
"Geoff Berrow" <bl******@ckdog.co.uk> wrote in message
news:kr********************************@4ax.com...
I noticed that Message-ID:
<3a**************************@posting.google.com > from LRW contained the
following:
if ($del) {
foreach ($del as $v) {
$sqldel = "delete from orderscart where id = '".$v."' and
ordernum = '".$ordernum."'";
$result = @mysql_query($sqldel, $dbconn);
}
}

Works great!


Yeah, the only thing I don't like about that is that it works too well.
I like to have an intermediate screen asking me if I'm sure I want to
delete these records.


Oh, good point. I'll take a closer look at the other methods; see if I can
suss them out.
Thanks,
Liam
Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Nik Coughin | last post: by
1 post views Thread by Oleg Konovalov | last post: by
3 posts views Thread by aparth | last post: by
8 posts views Thread by dude | last post: by
8 posts views Thread by T. Wintershoven | last post: by
5 posts views Thread by hugonot | last post: by
4 posts views Thread by mab464 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.