Form in a loop
Posted: Tue May 02, 2006 8:18 am
Hi all,
I need help bad here please. I trying to write a shopping cart, specific to me company.
How does one set variables when looping through php generated html?.. i.e:
I have an array
Then I create the listing (with html formating)
Please ignore the few other variables placemarkers, I've copied and pasted this code from my work.
So how do setup the Remove and Update buttons for each item in the list. I know how to write the code to do the actual removing and updating, but how do set up the buttons themselves to work on it's own record.
Normally I'd use
(for the remove button for example).
I hope this makes sense. I am desperate... Any help or direction (I have looked all over the internet, trust me, whew) will be greatly appreciated.
Thank you in advance.
Clinton
I need help bad here please. I trying to write a shopping cart, specific to me company.
How does one set variables when looping through php generated html?.. i.e:
I have an array
Code: Select all
$arr = array(1, 2, 3); // would be a query from a database.
foreach ($arr as $v) {
fctShowItem ($v);
}Code: Select all
<?php
function fctShowItem ($v) {
?>
... HTML code...
<tr><form name="form<?php echo $v; ?>"
method="post"
action="test.php">
<td width="63" valign="middle">
<input name="butRemove"
type="submit"
class="style14"
id="butRemove"
value="Remove">
</td>
<td width="86" height="20" valign="middle"><div align="right"><span class="style16"> Qty :</span>
<input name="textfield" type="text" class="style14" size="3" maxlength="3">
</div></td>
<td width="115" valign="middle"><div align="right"><span class="style16">Size :</span>
<input name="textfield2" type="text" class="style14" size="10" maxlength="10">
</div></td>
<td width="10" valign="middle"> </td>
<td width="57" valign="middle"><div align="right">
<input name="butUpdate"
type="button"
class="style14"
id="butUpdate"
value="Update">
</div></td>
<td width="54" valign="middle"><div align="right" class="style4">$Price</div></td>
</form>
</tr>
... A bit more HTML code, then ...
<?php
} // end fctShowItem
?>So how do setup the Remove and Update buttons for each item in the list. I know how to write the code to do the actual removing and updating, but how do set up the buttons themselves to work on it's own record.
Normally I'd use
Code: Select all
$butRemoveItem = isset($_REQUEST['butRemove']) ? true : false;
if ($butRemoveItem) {
// do something
}I hope this makes sense. I am desperate... Any help or direction (I have looked all over the internet, trust me, whew) will be greatly appreciated.
Thank you in advance.
Clinton