472,993 Members | 2,518 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,993 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 2177
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nik Coughin | last post by:
I am having a problem with checkboxes... I have a number of blocks like this on my form: <input type="text" name="name" value="a name"> <input type="text" name="ddi" value="1234"> <input...
3
by: Nath | last post by:
Please help!? I am new to writing html, javascript, pretty new to MySQL but quite proficient at writing Perl and i'm a quick learner. I am building a database driven website and i am a little...
1
by: Oleg Konovalov | last post by:
Hi, I am trying to pass a bunch of checked checkboxes (Javascript array) from page1 to the Java action class on subsequent web page (page2). (on page 1 I have a bunch of DB rows with a checkbox,...
3
by: aparth | last post by:
Hi, I'm having a problem simply putting the values of selected checkboxes into an array using javascript. The list of checkboxes is dynamically created so I need to count number of checkboxes in...
8
by: dude | last post by:
i'll try to be short ... i have this in html : <select name="OS" size="5"> <option value="0" selected>Please select one or more...</option> <option value="1">Windows</option> <option...
8
by: T. Wintershoven | last post by:
Hello all, I have a form with some checkboxes. The names of these checkboxes come from an array. When i click the submit button the resultcode doesn't recognize the names when i want to check...
5
by: hugonot | last post by:
I have got a problem with checkboxes array and the form. I have the results from table (MySQL) and checkbox (form) near the results. I use: echo "<input type=checkbox name=box value=".$.">"; for...
4
by: TechnoAtif | last post by:
Hi ALL I have entered some array values using checkboxes into mysql database through a form. Next iam creating a searchpage where all those cateogories inserted through checkboxes has to be...
4
by: mab464 | last post by:
I have this code on my WAMP server running on my XP machine if ( isset( $_POST ) ) { for($i=0; $i<count($_POST);$i++) { if ($ans != NULL ) $ans .= ", " . $_POST ; // Not the first...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

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.