doy51723 2017-03-20 07:08
浏览 13

在PHP中使用存储过程来获得排名

I have a store procedure that ranks a leaderboard table. How can I pull the rank of a specific userid from the array? This is the array my procedure dumps when I perform this query:

 $userposition = $wpdb->get_results("CALL addrank"); 
 print_r($userposition);

Array Output:

Array ( [0] => stdClass Object ( [userid] => 11 [Result] => 69 [Bonus] => 0 [Total] => 69 [Rank] => 1 ) [1] => stdClass Object ( [userid] => 32 [Result] => 38 [Bonus] => 0 [Total] => 38 [Rank] => 2 ) [2] => stdClass Object ( [userid] => 37 [Result] => 38 [Bonus] => 0 [Total] => 38 [Rank] => 2 ) [3] => stdClass Object ( [userid] => 7 [Result] => 38 [Bonus] => 0 [Total] => 38 [Rank] => 2 ) [4] => stdClass Object ( [userid] => 19 [Result] => 38 [Bonus] => 0 [Total] => 38 [Rank] => 2 )

Thanks in advance for the help.

  • 写回答

1条回答 默认 最新

  • douyun1972 2017-03-20 09:27
    关注
    <?php 
    foreach($userposition as $row):
        echo $row['userid']." -> ".$row['Rank']."<br>";
    endforeach;
    ?>
    
    评论

报告相同问题?