smarty计算

w6mmgewl  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(314)

我试图根据数据库值进行计算。基本上,我是按照我的代码显示一些数据 tpl 文件

<table cellpadding="2" cellspacing="0"> 

{foreach from=$data item=item key=key} 

  <tr> 
      <td>{$item.Country}</td> <td>{$item.count}</td> <td>{$item.sum}</td> 
  <tr> 

 {/foreach} 

</table>

现在我需要根据 {$item.count} 以及 {$item.sum} 通过搜索我在下面找到了 smarty math calculation formula ```
{* $height=4, $width=5 *}
{math equation="x + y" x=$height y=$width}

但是不能分配我的数据库变量。我该怎么做
q5iwbnjs

q5iwbnjs1#

你可以做基本的数学没有数学函数。

{assign var=x value=12}
{assign var=y value=4}
{assign var=sum value=$x+$y}
{assign var=difference value=$x-$y}
{assign var=product value=$x*$y}
{assign var=quotient value=$x/$y}
{assign var=modulo value=$x/$y}
{assign var=operations value=(($x/$y)*($x-$y)*9)-1}
<p>{$x} + {$y} = {$sum}</p>
<p>{$x} - {$y} = {$difference}</p>
<p>{$x} * {$y} = {$product}</p>
<p>{$x} / {$y} = {$quotient}</p>
<p>{$x} % {$y} = {$modulo}</p>
<p>(({$x}/{$y})*({$x}-{$y})*9)-1 = {$operations}</p>

相关问题