Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 智能总金额_Php_Smarty_Smarty3 - Fatal编程技术网

Php 智能总金额

Php 智能总金额,php,smarty,smarty3,Php,Smarty,Smarty3,如果我有以下代码,如何计算最终支付价格 总计$ : {foreach from=$items key=k item=item} {$item.Title} {$item.quantity} {$item.Price}。 {math equation=“x*y”x=$item.Price y=$item.quantity}。 {/foreach} ${$Total} 最好使用MySQL查询和GROUP BY,如果单个金额存储在DB中在ur循环中使用赋值,并将值添加到变量{$total} {ass

如果我有以下代码,如何计算最终支付价格

总计$

:

{foreach from=$items key=k item=item}
{$item.Title}
{$item.quantity}
{$item.Price}。
{math equation=“x*y”x=$item.Price y=$item.quantity}。
{/foreach}

${$Total}

最好使用MySQL查询和GROUP BY,如果单个金额存储在DB中

在ur循环中使用
赋值
,并将值添加到变量{$total}

{assign var=total value=0}

最好在php中循环使用ur数组,如果数据来自数据库,则计算总数,然后查询
sum

我不明白为什么需要它,但请执行以下操作:

注意:适用于Smarty 3

{$Total = 0 }  

{foreach from=$items key=k item=item}
        <tr>
          <td class="align_left"><strong>{$item.Title}</strong></td>
          <td><a href="products/view/{$k}"><img src="products_images/{$item.ImagePath}" width="60" height="60" alt="{$item.Title}" /></a></td>
          <td>{$item.quantity}</td>
          <td>{$item.Price}<span class="s_currency s_after"> лв.</span></td>
          <td>{math equation="x * y" x=$item.Price y=$item.quantity}<span class="s_currency s_after"> лв.</span></td>
          {$Total = $Total+ ($item.Price*$item.quantity) }
        </tr>              
     {/foreach}
     <tr class="last">
         <td class="align_right" colspan="4"><strong>Всичко:</strong></td>
         <td class="s_secondary_color"><span class="s_currency s_before">$</span>{$Total}</td>
    </tr>
{$Total=0}
{foreach from=$items key=k item=item}
{$item.Title}
{$item.quantity}
{$item.Price}。
{math equation=“x*y”x=$item.Price y=$item.quantity}。
{$Total=$Total+($item.Price*$item.quantity)}
{/foreach}

${$Total}

非常感谢伏都教417
{$Total = 0 }  

{foreach from=$items key=k item=item}
        <tr>
          <td class="align_left"><strong>{$item.Title}</strong></td>
          <td><a href="products/view/{$k}"><img src="products_images/{$item.ImagePath}" width="60" height="60" alt="{$item.Title}" /></a></td>
          <td>{$item.quantity}</td>
          <td>{$item.Price}<span class="s_currency s_after"> лв.</span></td>
          <td>{math equation="x * y" x=$item.Price y=$item.quantity}<span class="s_currency s_after"> лв.</span></td>
          {$Total = $Total+ ($item.Price*$item.quantity) }
        </tr>              
     {/foreach}
     <tr class="last">
         <td class="align_right" colspan="4"><strong>Всичко:</strong></td>
         <td class="s_secondary_color"><span class="s_currency s_before">$</span>{$Total}</td>
    </tr>