Help: Get The Name Of CheckBoxes That Is Checked In A Search

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
hadi_n3065
Forum Newbie
Posts: 2
Joined: Mon Dec 29, 2008 1:30 pm

Help: Get The Name Of CheckBoxes That Is Checked In A Search

Post by hadi_n3065 »

Hi

I print out rows from a database in a table like this

echo '<form action="" method="POST">';
for($i=0;$i<$num;$i++)
{
echo '<tr>';

echo '<td style="width: 300px" class="style11">
<span lang="en" class="style13"><a href="HomeDetails.php">Description</a></span></td>';

$record=mysql_result($result,$i,'Price');
echo '<td style="width: 300px" class="style15">
<span lang="en" class="style13"><strong>'.$record.'</strong></span></td>';

$record=mysql_result($result,$i,'Space');
echo '<td style="width: 300px" class="style15">
<span lang="en" class="style13"><strong>'.$record.'</strong></span></td>';

$record=mysql_result($result,$i,'City');
echo '<td style="width: 400px" class="style15">
<span lang="en" class="style13"><strong>'.$record.'</strong></span></td>';

$record=mysql_result($result,$i,'State');
echo '<td style="width: 400px" class="style15">
<span lang="en" class="style13"><strong>'.$record.'</strong></span></td>';

$record=$i+1;
echo '<td style="width: 100px" class="style15">
<span lang="en" class="style13"><strong>'.$record.'</strong></span></td>';

$record=mysql_result($result,$i,'ID');
echo '<td class="style15"style="width: 100px" class="style11">
<input type="checkbox" name=chckbx'.$record.'></td>';

echo '</tr>';

}//end of for
echo '</table></div><input type="submit" name="BtnDel" value="Delete"></form>';

Now I want to submit this form to the next page and there I want to delete all rows where the checkbox have been checked.

My problem is: How do I get the selected ones?

Let's say that row1 and row 3 is checked. Then I would like to get the value 1 and 3 so I can remove the rows in the database with this id.

On this page there will be a lot of other checkbox.(If that is possible?)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Help: Get The Name Of CheckBoxes That Is Checked In A Search

Post by josh »

According to http RFCs, if the checkbox is set a property will be set in GET or POST with the value of the input, if it is not checked the parameter will not be sent.
User avatar
volomike
Forum Regular
Posts: 633
Joined: Wed Jan 16, 2008 9:04 am
Location: Myrtle Beach, South Carolina, USA

Re: Help: Get The Name Of CheckBoxes That Is Checked In A Search

Post by volomike »

hadi:

I think this translates into...

I have this form with a bunch of checkboxes on it. I'm having trouble when I post this form in identifying what was checked off or not.

The only thing you're doing wrong is that you're not assigning a 'value' attribute in your checkboxes, such as:

Code: Select all

<input type="checkbox" name=chckbx' . $record . ' value="' . $record . '">'
Now your $_POST will give you a set of record IDs that you can then delete. You just iterate through $_POST like so:

Code: Select all

foreach ($_POST as $sKey => $sVal) {
  if (strpos(' ' . $sKey, 'chckbox')>0) {
    $sIDToDelete = $sVal;
    DeleteMyRecord($sIDToDelete);
  }
}
hadi_n3065
Forum Newbie
Posts: 2
Joined: Mon Dec 29, 2008 1:30 pm

Re: Help: Get The Name Of CheckBoxes That Is Checked In A Search

Post by hadi_n3065 »

Hi mike
my problem solved with your code.
Thank you very much.
bYe
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Re: Help: Get The Name Of CheckBoxes That Is Checked In A Search

Post by Bill H »

And for future reference, this question was in the wrong forum; should have been on the code forum. This forum has in its title,
"This forum is not for asking programming related questions."
Post Reply