我正在尝试向活跃点上的顶级用户展示,我只能获得使用此代码的顶级用户
<?php
$dbase = Phpfox::getLib('database');
$aRow = $dbase->select(Phpfox::getUserField() . ', ur.activity_points AS score')
->from(Phpfox::getT('user'), 'u')
->join(Phpfox::getT('user_activity'),'ur','ur.user_id = u.user_id')
->where('ur.activity_points > 0')
->limit(10)
->order('ur.activity_points DESC')
->execute('getRow');
?>
<?php if (count ( $aRow )){ ?>
<div class="block" id="js_sortable_friend_mini"><div class="title ">Top Active Users</div>
<div class="clear" style="height: 5px;"></div>
<ul id="topuserpoints">
<div class="name_userpoints">
<?php echo '<a href="' . Phpfox::getLib('phpfox.url')->makeUrl('profile', $aRow['user_name']) . '">' . $aRow['full_name'] . '</a>'; ?>
</div>
<div class="score_userpoints">
<?php echo $aRow['score']; ?>
</div></ul>
</div>
<div class="clear"></div>
<?php } unset($aRow); ?>
此代码仅提供顶级用户。但我想要前5名。请帮忙
答案 0 :(得分:0)
尝试使用&#34; getRows&#34;执行并将限制设置为5,如果你想要5个最佳:
......
->limit(5)
->order('ur.activity_points DESC')
->execute('getRows');
.....
答案 1 :(得分:0)
您可以在查询中尝试使用getRows或getSlaveRows而不是getRow。
->execute('getRow');
getRow只返回一条记录,getRows将返回多条记录。
以下代码用于显示基于活动点的排名选项。
$dbase = Phpfox::getLib('database');
$aRow = $dbase->select(Phpfox::getUserField() . ', ur.activity_points , FIND_IN_SET( activity_points, ( SELECT GROUP_CONCAT( DISTINCT activity_points ORDER BY activity_points DESC ) FROM '.Phpfox::getT('user_activity').')) AS rank ')
->from(Phpfox::getT('user'), 'u')
->join(Phpfox::getT('user_activity'),'ur','ur.user_id = u.user_id')
->where('ur.activity_points > 0')
->limit(10)
->order('rank')
->execute('getRows');