0

I am trying to show top users on activity points, i can get only top user using this code

<?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); ?>

This code give only the top user. but I want top 5. please help

temmy
  • 1

2 Answers2

0

Try to execute with "getRows" and set limit to 5, if you want 5 of best:

               ......
                ->limit(5)         
                ->order('ur.activity_points DESC')
                ->execute('getRows'); 
              .....
Ali insan Soyaslan
  • 836
  • 5
  • 14
  • 33
  • dear sir, thank you for your reply, but 5 does not give me the required result. this code is showing the top most user only, i want to show top 5 users. any idea? please help – temmy Dec 27 '14 at 11:46
  • Are u sure you have at least 5 users in your database and their points are diffrent than 0? – Ali insan Soyaslan Dec 27 '14 at 11:50
  • yes sir there are a lot of users. moreover, i want to show the current users position of that list – temmy Dec 27 '14 at 11:53
  • Sir is there way to run a loop? like foreach? – temmy Dec 27 '14 at 14:58
0

Can you try with getRows or getSlaveRows instead of getRow in your query.

->execute('getRow');  

getRow will return only one record, getRows will return more than one.

Below code is for display Rank option based on activity points.

$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');  
Alex
  • 11,115
  • 12
  • 51
  • 64