Post #39 is an example. You need to actually read what I wrote and apply it to your code.
Printable View
Post #39 is an example. You need to actually read what I wrote and apply it to your code.
Sorry, I have added to my last post!
Edit:
It seems that the loop is not being triggered! I manual put the total in for the previous two rows and it works. However for some reason the loop only counts the final row in the table and not the rows before it. This is the code I'm using:
The above code has the "$total_amount" variable set to the total of the first two rows I was using. The unedited code is here.PHP Code:for ($i=0; $i < $depth; $i++)
{
$item = $cart->get_item($i);
$deleted = $item->deleted;
if (!$deleted){
$item_id = $item->get_item_id();
$item_name = $item->get_item_name();
$qty = $item->get_qty();
$price = $item->get_price();
$total_amount = 170;
$total_amount = $total_amount +($price*$qty);
echo"<tr><td>$item_name</td><td>$qty </td><td>$price</td></tr>";
}
}
you initialised $totalAmount, but you're referring to $total_amount in the actual code. now, I don't know what else you're talking about here, so I'm going to just assume this will fix your initial problem!
like visualAd and I have been saying, you should be initialising your integer values as a ZERO. you don't initialise it as an equation. treat it like you would another language, if you must, by explicitly declaring every variable you're using at the top of your script:
PHP Code:<?php
//declarations
$type = '';
$whatever = 0;
$total_amount = 0;
//rest of my code goes here
Thanks! That worked Although, I'm a bit confused as to why the same code doesn't work when I put "var" in front of it (see post #38)?
Edit:
Reading the php manual var on its own is not a keyword unlike in a language such as Visual Basic.
the var keyword is for declaring/initialising variables within a class (although not within a method). however, the var keyword is deprecated in PHP5; you can use the public, private or protected keywords instead. this is all about object oriented programming and I'd assume is over your head at this point.
if you want to declare a variable outside of a class, you can just assign it a value. this isn't javascript :)