Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default [PHP] Is there any way to sort this easily?

    PHP Code:
    $query mysql_query("SELECT * FROM stats ORDER BY $getid DESC"); 
    $getid can be either points, rebounds, or assists (already rows in the table). I also have another row called games. What I want to add is a way to calculate PPG, RPG, APG (points/rebounds/assists per game). The formula is points/reb/ast divided by the number of games. I don't want to store it in the database. Is there any easy way to do this?

    Would it be possible to do:
    PHP Code:
    mysql_query("SELECT * FROM stats ORDER BY '$getid / $games' DESC"); 
    Vouches
    [x][x]

  2. #2
    Join Date
    Nov 2008
    Location
    Cambridge, UK
    Posts
    901
    Tokens
    100

    Default

    What are you on about?
    we're smiling but we're close to tears, even after all these years

  3. #3
    Join Date
    Apr 2010
    Location
    Newcastle
    Posts
    655
    Tokens
    50

    Default

    I'm not 100% sure what you're asking, I'm assuming it's a leader-board?

    I'm also not that great with SQL but I'll give it a shot..

    PHP Code:
    $query=mysql_query("SELECT (`$getid`/`games`),`$getid`,* FROM `stats` ORDER BY (`$getid`/`games`) DESC");
    while(
    $row=@mysql_fetch_array($query)){
    echo 
    "<b>Games:</b> {$row['games']}<br /><b>".ucwords(strtolower($getid)).":</b> {$row[1]}<br /><b>Ratio:</b> {$row[0]}<hr />";

    Note the funny looking back quotes: ``.

    Then if you wanted username to be displayed as well, you'd use a JOIN.

  4. #4
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    <?php
    $total = $getid/$games;
    mysql_query("SELECT * FROM `stats` ORDER BY $total DESC");
    ?>
    Something along those lines...

    Lew.
    Im not here to be loved, I love to be hated :-}


  5. #5
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    It's a basketball stats script, to keep track of player's stats throughout the season, hence the points, rebounds, assists.

    Thanks for that snippet, I'll try it out. I tried something similar to it earlier but it didn't work though.
    Vouches
    [x][x]

  6. #6
    Join Date
    Nov 2008
    Location
    Cambridge, UK
    Posts
    901
    Tokens
    100

    Default

    The ORDER BY clause is used to order the results of the query and must, therefore, be a valid column in your table. So if the EXACT value of '$getid/$games' isn't a valid column reference, it isn't going to work.

    I think the best move would be to stop overcomplicating things; simply lift the needed data from the table and use simple PHP calculations to work out what you need.
    we're smiling but we're close to tears, even after all these years

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •