功能:在任何需要的地方调用户公司排行,按该公司某个频道所发布的信息数量排序,发的多得排前面。
步骤:
在公共函数文件中添加以下函数
路径 include/global.func.php
function ask_fxb($page) {
global $db;
$cat = array();
$page = intval($page);
$result = $db->query("selec b.username,b.linkurl,b.company,count(itemid) as nums from {$db->pre}know_answer as a,{$db->pre}company as b wher a.username = b.username group by b.userid order by nums desc LIMIT 0,$page", 'CACHE');
while($r = $db->fetch_array($result)) {
$cat[] = $r;
}
return $cat;
}
在模板中调用
{php $tags=ask_fxb(3);}
{loop $tags $i $t}
{$i+1}
[{$t[nums]}]
{/loop}
以上实例为我做项目时调用的问答频道回答数排名,调用数量为三条,如需要修改调用数量,修改ask_fxb(3)中的3即可。
函数解析:
如果要按用户在其它频道的发布数量排名,把{$db->pre}know_answer 改成其它频道的表即可,如供应的是 {$db->pre}sell_5 求购的是 {$db->pre}buy_6
function ask_fxb($page) {
global $db;
$cat = array();
$page = intval($page);
$result = $db->query("selec b.username,b.linkurl,b.company,count(itemid) as nums from {$db->pre}know_answer as a,{$db->pre}company as b wher a.username = b.username group by b.userid order by nums desc LIMIT 0,$page", 'CACHE');
while($r = $db->fetch_array($result)) {
$cat[] = $r;
}
return $cat;
}
inkurl]}" target="_blank">{$t[company]}律师