Jump to content

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


hadi_n3065

Recommended Posts

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?)

 

Thanks , Hadi

change this:

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

to

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

 

then in your processing code, loop over $_POST['chkbx']:

foreach(array_keys($_POST['chkbx']) as $id){
  echo "Item $id was checked<br>";
}

 

edit: fixed my foreach

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.