SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: Help finding value of array
-
Oct 11, 2006, 12:34 #1
- Join Date
- Sep 2003
- Location
- Wylie, TX
- Posts
- 129
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Help finding value of array
I've built a simple shopping cart and need to generate the total shipping from the array. Here is code so far.
PHP Code:<?
while (list($key, $val) = each($_SESSION['cart'])) {
$this_item = $key;
$this_item_qty = $val;
echo ('<tr valign="top">');
echo ('<td>' . $items[$this_item].'</td>');
echo ('<td align="right">$');
echo (number_format($prices[$this_item],2));
echo ('</td>');
echo ('<td>');
if(!$this_item_qty) {
$this_item_qty = 1;
}
echo $this_item_qty;
echo '</td>';
echo ('<td>$'. $shipping[$this_item] .'</td>');
$this_line_total = $this_item_qty * (number_format($prices[$this_item],2) + $shipping[$this_item]);
echo ('<td>$'. number_format($this_line_total,2) . '</td>');
echo ('</tr>');
$total = $total + $this_line_total;
$shippingtotal = // BLAH, BLAH ??
}?>
-
Oct 11, 2006, 12:36 #2
- Join Date
- Mar 2006
- Posts
- 6,132
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
i didnt look too closely at your code, but i guess you have an individual shipping charge per item.
here is the logic.
PHP Code:$shipping_total = 0;
while(...) {
$shipping_total =+ $shipping_charge_for_this_item;
}
echo $shipping_total;
-
Oct 11, 2006, 13:04 #3
- Join Date
- Sep 2003
- Location
- Wylie, TX
- Posts
- 129
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks clamcrusher, however I'm still not getting this.
I am already inside a while loop. When I try another while loop it times out.
I tried this
PHP Code:if($items[$this_item] < 1 ) {
$shippingtotal = + $shipping[$this_item];
}
-
Oct 11, 2006, 13:10 #4
- Join Date
- Mar 2006
- Posts
- 6,132
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
btw i made a typo, it should be += not =+
PHP Code:
$shipping_total = 0;
while (list($key, $val) = each($_SESSION['cart'])) {
// your other code...
$shipping_total += $shipping_charge_for_this_item;
// your other code....
}
echo $shipping_total;
-
Oct 11, 2006, 13:18 #5
- Join Date
- Sep 2003
- Location
- Wylie, TX
- Posts
- 129
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank you very much, I got it to work. I was under the impression I needed to do some sort of count for that array.
Bookmarks