views:

146

answers:

2

The key code is:

  while ($row= mysql_fetch_array($result, MYSQL_ASSOC))
{ $id=$row[id];
  $html=<<<html
<tr><td> 
<input style="float:left" type="checkbox" name="mycheckbox[]"  value="$id">   
<span style="float:left">$row[content]</span>
<span style="color:black;float:right">$row[submitter]</span></td></tr>  
html;
echo $html; 
}

There are many checkboxes.

How to receive these checkbox values in another PHP file?

You know, you need to name these checkboxes so a PHP file can receive these values on the other side. But how to name these checkboxes? If I name 1,2, 3,...,how can I associate them with $row[id]?

+1  A: 

You need to give them names - you can either do it like this:

<input style="float:left" type="checkbox" id="$id" name="$id" value="true">

or like this to get an array:

<input style="float:left" type="checkbox" id="$id" name="myBoxes[$id]" value="true">

You can then check isset($_POST[$id]) or isset($_POST['myBoxes'][$id])

Greg
$id is a variable whose values are random, how can you know the values of the variable?
Steven
If you use the myBoxes way you can `foreach ($_POST['myBoxes'] as $id => $value) { ... } `
Greg
Can I get an element's name via its id?
Steven
Erm how do you mean/
Greg
A: 

Name your checkboxes so you can easily identify them. eg

 $CheckBoxHTML =  "<input type='checkbox' name='check_$row[id]' value='YES'>Check This";

then in your recieving php file you can find all checkboxes by

foreach ($_POST as $key => $value)
{
  if (strpos($key,'check_') !== false)
  {
     list($tmp, $ID) = split('_', $key);

      $CheckedValues[] = $ID;

   } 

}

That will pull out all your checked ids.

Toby Allen