Jump to content

Recommended Posts

Hi, i have a shopping basket that uses a for loop to show contents of the basket. There is then a qty field for each item with the name of the field being qty and the value of $i in the for loop. I need to be able to refer to this field on the next page using the same loop to show the final values.

The problem i have is being able to reference qty1 for example. How can i get the form field of name qty$i?

Here is an example of code from the second page
[code]<?
for ($i=1 ; $i <= $_SESSION["item_count"]; $i++) {
$item_cost = $_SESSION["item_cost[$i]"];

?>
<tr>

<td><?php echo $_SESSION["items_tray[$i]"]; ?></td>
<td align=center><?php echo $_SESSION["quantity[$i]"]; ?></td>
<td align=center>£<?php echo number_format("$item_cost","2",".",","); ?></td>
<td align=center>£<? echo (number_format(($item_cost * $qty$i),"2")); ?></td>
</tr>
<? } ?>[/code]

obviously this doesnt work, can someone help me as im really stuck!

Link to comment
https://forums.phpfreaks.com/topic/14573-urgent-help-required/
Share on other sites

I'm not entirely sure if you can use square brackets like you have within your session array. You could try one of the following:
[code]<?php
$_SESSION["quantity$i"];
$_SESSION["quantity".$i];
$_SESSION["quantity{$i}"];
?>[/code]
[b]EDIT:[/b] Or, yes, use wildteen88s method if you have a multi-dimensional array, I [i]may[/i] have misunderstood what you were trying to achieve.
Link to comment
https://forums.phpfreaks.com/topic/14573-urgent-help-required/#findComment-57824
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.