请问:php运算时为什么只算两条数据相加呢?如何才能算出所有数的和?

新手上路,请多包涵

这是finecms 的模板,有这样的一个循环,展示的是会员发内布的交易信息,每个信息里面又有其他会员的回复,这个回复里有金额,用PHP写了个运算(只是显示,没写入数据库),可是它只算两条以内的和,如何能让每个信息里的所有回执金额相加成总数呢?

{list modelid=27 order=updatetime num=10 more=1}
{php $id = $t['id'];}
<a href="{$t['url']}">
<li style="position:relative;">
<div class="jyxx">{strcut(strip_tags($t['shangjia']),12,"")}</div><div class="jyxx">{strcut(strip_tags($t['title']),12,"")}</div><div class="jyxx">{strcut(strip_tags($t['jiaoyixiangmu']),12,"")}</div><div class="jyxx">¥{$t['jiaoyijine']}元</div>
{list form=jiaoyi cid=$id order=id return=d}
<?php $a= $d['huizhijine']; $g = $d['lingqubili']; $dd = $c; $c = $a *100 /$g;  $dd +=$c;  $e = $d['jiaoyijine'] - $dd; $f = $e *$g /100; $h = $dd /$t['jiaoyijine'] *100;?>
<h1 class="indhz">最近领取:{date("Y年m月d日",$d['updatetime'])}来{$d['huizhishangjia']}领取{$d['huizhijine']} 元 {$d['huizhichanpin']}--计{$c}</h1>
{/list}
总{$dd}
</li>
</a>
{/list}

图片说明

阅读 1k
1 个回答

因为你的$dd变量定义在了循环里了,所以每次循环都会重置

{list modelid=27 order=updatetime num=10 more=1}
{php $id = $t['id'];}
<a href="{$t['url']}">
<li style="position:relative;">
<div class="jyxx">{strcut(strip_tags($t['shangjia']),12,"")}</div><div class="jyxx">{strcut(strip_tags($t['title']),12,"")}</div><div class="jyxx">{strcut(strip_tags($t['jiaoyixiangmu']),12,"")}</div><div class="jyxx">¥{$t['jiaoyijine']}元</div>
<?php $dd=0;?>
{list form=jiaoyi cid=$id order=id return=d}
<?php $a= $d['huizhijine']; $g = $d['lingqubili']; $ddt = $c; $c = $a *100 /$g;  $ddt +=$c;  $e = $d['jiaoyijine'] - $ddt; $f = $e *$g /100; $h = $ddt /$t['jiaoyijine'] *100;$dd+=$ddt;?>
<h1 class="indhz">最近领取:{date("Y年m月d日",$d['updatetime'])}来{$d['huizhishangjia']}领取{$d['huizhijine']} 元 {$d['huizhichanpin']}--计{$c}</h1>
{/list}
总{$dd}
</li>
</a>
{/list}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏