【问题标题】:how to show top 5 users in phpfox如何在phpfox中显示前5名用户
【发布时间】:2014-12-27 11:35:38
【问题描述】:

我正在尝试向顶级用户展示活动点数,我只能使用此代码获得顶级用户

<?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 名。请帮忙

【问题讨论】:

    标签: phpfox


    【解决方案1】:

    尝试使用“getRows”执行并将限制设置为 5,如果您想要最好的 5 个:

                   ......
                    ->limit(5)         
                    ->order('ur.activity_points DESC')
                    ->execute('getRows'); 
                  .....
    

    【讨论】:

    • 尊敬的先生,感谢您的回复,但 5 并没有给我所需的结果。此代码仅显示最高用户,我想显示前 5 名用户。任何想法?请帮忙
    • 您确定您的数据库中至少有 5 个用户并且他们的点数与 0 不同吗?
    • 是的,先生,有很多用户。此外,我想显示该列表的当前用户位置
    • 先生有没有办法运行一个循环?喜欢 foreach?
    【解决方案2】:

    您能否在查询中尝试使用 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');  
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-30
      • 2021-11-18
      • 1970-01-01
      • 2015-09-20
      • 2013-07-13
      • 2015-02-23
      • 1970-01-01
      • 2019-02-24
      相关资源
      最近更新 更多