Reputation: 25284
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?
Upvotes: 0
Views: 385
Reputation: 32145
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/>';
Upvotes: 2