Using Multiple CheckBoxes in a Table
Posted: Thu Jun 13, 2002 9:01 pm
I wish to present a <form> to users containing a <table> where each <tr> contains the following product details:
id, description, price, and a checkbox against each row.
the form has a submit button
I am able to do this much. (code at bottom)
In respect of the form and its action, how do I make the checkbox in each row correspond to the correct record to perform the action on.
Do I add the record id to the name of the checkbox so that a variable exists once the form is submitted.
Any assistance would be greatly appreciated.
- Andrew
CODE:
<?
$query = "SELECT id, description, price FROM products";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
if ($num_results ==0)
{
echo "No matching items found";
exit;
}
?>
available products<BR><BR>
<FORM method="POST" action="prodfindstep5.php">
<TABLE>
<?
while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
print "\t<TR>\n";
foreach ($line as $col_value)
{
print "\t\t<TD>$col_value</TD>\n";
}
?>
<TD><INPUT type="checkbox"></TD>
<?
print "\t</tr>\n";
}
?>
<TR><TD align="center" colspan="4"><INPUT type="submit" value="more info"></TD></TR>
</TABLE>
</FORM>
<?
}
?>
id, description, price, and a checkbox against each row.
the form has a submit button
I am able to do this much. (code at bottom)
In respect of the form and its action, how do I make the checkbox in each row correspond to the correct record to perform the action on.
Do I add the record id to the name of the checkbox so that a variable exists once the form is submitted.
Any assistance would be greatly appreciated.
- Andrew
CODE:
<?
$query = "SELECT id, description, price FROM products";
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
if ($num_results ==0)
{
echo "No matching items found";
exit;
}
?>
available products<BR><BR>
<FORM method="POST" action="prodfindstep5.php">
<TABLE>
<?
while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
print "\t<TR>\n";
foreach ($line as $col_value)
{
print "\t\t<TD>$col_value</TD>\n";
}
?>
<TD><INPUT type="checkbox"></TD>
<?
print "\t</tr>\n";
}
?>
<TR><TD align="center" colspan="4"><INPUT type="submit" value="more info"></TD></TR>
</TABLE>
</FORM>
<?
}
?>