Hi,
I'm fairly new to PHP and really need some help with the following code.
I need some kind of loop or array that will help me add multiple shopping cart items to a form.
This is the code I am currently using...
The issue is that for each item in the shopping cart I need the name of the form field to increase by 1.
So if if there were 3 items in the shopping cart the form would need to display like this
Does that make sense?
Really appreciate any help
Thanks
Elle
I'm fairly new to PHP and really need some help with the following code.
I need some kind of loop or array that will help me add multiple shopping cart items to a form.
This is the code I am currently using...
Code:
<? foreach ($invoice->cart->items as $id => $item) {
?>
<input type="hidden" name="item_name_1" value="<?=$item->name?>">
<input type="hidden" name="item_number_1" value="<?=$id?>">
<input type="hidden" name="quantity_1" value="<?=$item->qty?>">
<input type="hidden" name="amount_1" value="<?=number_format($item->price, 2)?>">
<? } ?>
The issue is that for each item in the shopping cart I need the name of the form field to increase by 1.
So if if there were 3 items in the shopping cart the form would need to display like this
Code:
<input type="hidden" name="item_name_1" value="yellow food box">
<input type="hidden" name="item_number_1" value="SKU023">
<input type="hidden" name="quantity_1" value="1">
<input type="hidden" name="amount_1" value="85.00">
<input type="hidden" name="item_name_2" value="Red food box">
<input type="hidden" name="item_number_2" value="SKU012">
<input type="hidden" name="quantity_2" value="1">
<input type="hidden" name="amount_2" value="85.00">
<input type="hidden" name="item_name_3" value="Black food box">
<input type="hidden" name="item_number_3" value="SKU035">
<input type="hidden" name="quantity_3" value="1">
<input type="hidden" name="amount_3" value="85.00">
Does that make sense?
Really appreciate any help
Thanks
Elle