473,395 Members | 1,343 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 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 2196
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.