我试图在活动点显示顶级用户,我只能获得顶级用户使用此代码
<?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名,请帮帮忙
发布于 2014-12-27 19:43:20
尝试使用"getRows“执行,并将limit设置为5,如果您想要最好的5:
......
->limit(5)
->order('ur.activity_points DESC')
->execute('getRows');
.....发布于 2015-03-17 18:00:30
您可以尝试在查询中使用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'); https://stackoverflow.com/questions/27666837
复制相似问题