Ask a master about the Smarty problem!!!
The following is an array of shopping carts
$carts =array (
1=>array (name=> "Nokia 5510", price=>800, Qty=>2),
3=>array (name=> "Nokia 6610", price=>1800, Qty=>1),
4=>array (name=> "Nokia 7710", price=>2800, Qty=>1),
7=>array (name=> "Nokia 8810", price=>2500, Qty=>5),
}
Use the Smarty Loop, display the shopping cart in tabular form, the table row background color has the rotation effect, the table has the total statistics
------Solution--------------------
Do the addition in the PHP page and pass in the Smarty template. Smarty doesn't seem to be calculating.
Loop Add-out
$sum
$smarty->assign ("sum", $sum);
Total amount: {$sum}
------Solution--------------------
I checked the manual and can calculate
In math [math] {assign var= "foo" value= "' $foo + $bar '"}
Your template can be written like this
HTML Code
<title>Untitled Document</title>
Name |
Price |
Number |
{foreach from= $carts key=k item=item0} {if $k% 2}
{Else}
{/if} {foreach from= $item 0 item=item1}
{$item 1} | {/foreach}
{Assign var= "sum" value= "' $sum + $item 0.price '"} {/foreach}
Total amount: {$sum} |
------Solution--------------------
If you want to do multiplication
{Assign var= "sum" value= "' $sum + $item 0.price* $item 0.qty '"}