2016-03-18 68 views
0

所以我在我的網站上有這個功能,人們可以去頂級用戶選項卡,它會顯示在我的網站上獲利最多的人。爲sql數據庫提取信息

使用此代碼

<?php 

$rs1 = mysql_query("SELECT profit,steamid,name,avatar FROM `users` GROUP BY profit DESC LIMIT 1");      
$row = mysql_fetch_row($rs1); 
$profit = round($row[0],2); 
$steamid = $row[1]; 
$name = $row[2]; 
$avatar = $row[3]; 

    echo'      
     <div class="col-md-4 col-lg-4"> 
      <div class="widget-bg-color-icon card-box"> 
        <a href="profile.php?action=view&id='.$steamid.'" target="_BLANK"><img src="https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/e3/'.$avatar.'" width="100px" alt="user-img" class="img-circle hoverZoomLink"> 
        <h2>'.$name.'</h2></a> 
        <p><font color="#01DF01">$'.$profit.'</font></p> 
        <div><font color="white">Most Profit</font></div> 
      </div> 
     </div> 
    '; 

但我無法弄清楚如何從與第二大利潤用戶的信息。

網站:CSGOLog.com/topusers1.php

+2

**不要使用mysql_ *。**它已在PHP7中刪除。 – Drudge

+0

您應該先閱讀手冊...使用'ORDER BY'而不是'GROUP BY'。你爲什麼添加「LIMIT 1」?你應該得到你的數據在循環而不是'$ row = mysql_fetch_row($ rs1);'你應該[停止使用'mysql_ *'](http://stackoverflow.com/questions/12859942/why-shouldnt-i -use MySQL的函數式的PHP)。 – IROEGBU

+0

我沒有任何語言的教育,我只學會了通過論壇等進行編程 - 所以我很抱歉沒有閱讀「手冊」 –

回答

1

限制可以採取兩個參數

SELECT profit,steamid,name,avatar FROM `users` GROUP BY profit DESC LIMIT 1, 1 

它你使用相同的查詢,但與限制的附加參數。

根據我的理解,你應該在這裏使用ORDER BY而不是GROUP BY。