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>
<?
}
?>
Using Multiple CheckBoxes in a Table
Moderator: General Moderators
- roninblade
- Forum Newbie
- Posts: 21
- Joined: Thu Jun 13, 2002 7:12 pm
Re: Using Multiple CheckBoxes in a Table
yes add the record id, since it is the unique value of the record.dickey wrote: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.
i also agree with Peter, you should name the checkboxes as an array so you wont have any difficulty accessing the values later.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Following those ideas you should end up with something like:
Mac
Code: Select all
echo '<input type="checkbox" name="infoї]" value="'.$id.'" />';Using Multiple CheckBoxes in a Table
Thanks very much for your assistance Peter, Roninblade, and Twigletmac.
Named the checkboxes as an array as you suggested.
The array is only populated by those checkboxes that were checked, which makes processing very easy.
Thanks again.
Named the checkboxes as an array as you suggested.
The array is only populated by those checkboxes that were checked, which makes processing very easy.
Thanks again.