打开/include/global.func.php
在最后边加上以下代码:
function get_com($catid){ global $db; $sql = "select * from ".$db->pre."category where catid=".$catid.""; //调用当前栏目所有子分类 $result = mysql_query($sql); $catids = ''; while($count=mysql_fetch_array($result)) { $catids .= $count['arrchildid']; } $row = array(); $sql2 = "select a.username,a.userid,a.company, COUNT(b.itemid) AS com_num from ".$db->pre."member as a,".$db->pre."mall as b where a.username=b.username and b.catid in ($catids) GROUP BY b.username HAVINg com_num > 0 "; $result2 = mysql_query($sql2); while($count2 = mysql_fetch_array($result2)) { $row[] = $count2; } return $row; }
代码内容不解释
再打开你要用的模板,模板地方参考以下代码,自行修改
{php $cominfo=get_com($c[catid]);} {loop $cominfo $i $t} <a rel="nofollow" title="{$t[company]}" target="_blank" href="{userurl($t[username])}"><span>{$t[company]}</span></a> {/loop}
$c[catid]是上一层loop遍历出来的.把数据取出来了,遍历跟据自己情况写loop吧.