views:

130

answers:

1
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; 
}

Since the HTML code is generated dynamically, I don't know how long the array "mycheckbox" is and I don't know what checkboxes are ticked or unticked(This is determined by users). How to retrieve the values of ticked checkboxes using PHP?

+2  A: 

The way you have it now, mycheckbox will get overwritten and act more like a radio button.

You probably want:

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

PHP will push the checked values into an array: $_GET['mycheckbox']

<?php 

$values = $_GET['mycheckbox'];
$count = count($values);

echo 'Selected values are: <br/>';

foreach($values as $val) {
    echo $val . '<br/>';
}

echo 'Total Length is: ' . $count . '<br/>';
Mike B
How to write the PHP code?
Steven
With your keyboard.
Mike B
I love you Mike.
BraedenP
The problem has been resolved. Thank you, everyone!
Steven