Jump to content

[SOLVED] Help with PHP query


SocomNegotiator

Recommended Posts

Well I have some games that I am querying...here is the code

SELECT id,game FROM ladders ORDER BY game LIMIT 1

 

Now when I say limit 1 it actually limits it to one result. Well I want to limit it to one result for each game. Because I have more than one game, and some games are listed more than once. So I don't need the same game to come up twice. Any ideas what I can put...?

Link to comment
https://forums.phpfreaks.com/topic/101498-solved-help-with-php-query/
Share on other sites

Its generally faster to query only once. This is still less efficient than the query you want, but I can't figure this one out:

<?

$results = mysql_query('SELECT id, game FROM ladders');

$games = array();

while($row = mysql_fetch_assoc($results)){

    if(in_array($row['game'], $games)){

          // Do nothing, already used

    }else{

          // Do stuff.

          $games[] = $row['game'];

    }

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.