步骤:
在公共函数文件中添加以下函数
路径 include/global.func.php
//用户周积分排行,如要调用其它时间,如一个月,将SQL中的7改成30 function zhou($page) { global $db; $cat = array(); $page = intval($page); $result = $db->query("selec b.userid,b.areaid,b.username,sum(amount) as nums from {$db->pre}finance_credit as a,{$db->pre}member as b wher a.username = b.username and a.addtime>($DT_TIME-7*24*3600) and b.groupid>5 group by b.userid order by nums desc LIMIT 0,$page", 'CACHE'); while($r = $db->fetch_array($result)) { $cat[] = $r; } return $cat; }
模板中调用方法和实例:
{php $zhou = zhou(10);} {loop $zhou $i $t} <li> <strong class="hot">{$i+1}</strong> <a href="{ziliao($t[username],'linkurl')}" target="_blank" title="{ziliao($t[username],'company')}">{ziliao($t[username],'company')}</a> <span class="city">{area_pos($t[areaid], '-')}</span> <em>{$t[nums]}</em> </li> {/loop}
因为模板循环中调用了用户公司名称,还有主页地址,我使用的是函数单独查询方法,所以还得在公共函数文件中加入以下函数:
//会员资料 function ziliao($username,$name){ global $db; $row = $db->get_one("selec * from {$db->pre}company wher username='$username'",$cache); $name = $row["$name"]; return $name; }
另附赠用户总积分排行调用标签,总积分不需要计算积分流水,所以直接用标签就可以调用了
<!-- 总积分排行 --> <ul class="clearfix laywer-score hidden"> <!--{php $tags=tag("table=member&condition=groupid>5&pagesize=10&order=credit desc&template=null");}--> {loop $tags $i $t} <li> <strong class="hot">{$i+1}</strong> <a href="{ziliao($t[username],'linkurl')}" target="_blank" title="{ziliao($t[username],'company')}">{ziliao($t[username],'company')}</a> <span class="city">{area_pos($t[areaid], '-')}</span> <em>{$t[credit]}</em> </li> {/loop} </ul>