0

So I have this feature on my site that people can go to a top users tab and it will show the person with the most profit on my site.

Using this code

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

But I can't figure out how to retrieve the information from the user with the second most profit.

Website: CSGOLog.com/topusers1.php

  • 2
    **DO NOT USE mysql_* .** It has been removed in PHP7. – Drudge Rajen Mar 18 '16 at 10:27
  • You should read manuals first... use `ORDER BY` instead of `GROUP BY`. Why did you add `LIMIT 1`? You should get your data in a loop instead of `$row = mysql_fetch_row($rs1);` and you should [stop using `mysql_*`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). – IROEGBU Mar 18 '16 at 10:40
  • I have no education whatsoever in any language, I have only learned to program through forums etc - So I am so sorry for not reading the "manual" – Sebastian Ryen Mar 18 '16 at 16:26

1 Answers1

1

Limit can take two arguments

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

It the same query you used but with an additional parameter for limit.

According to my understanding you should use ORDER BY rather than GROUP BY here.

Techie
  • 44,706
  • 42
  • 157
  • 243