Jump to content

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

If ID is unique, and it sounds like it, then select distinct will return everything.

 

You could select ID within your sql results

 

SELECT DISTINCT game FROM ladders

while {

 

SELECT id FROM ladders where game = $dbgame LIMIT 1

 

}

 

This is conceptual of course.

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

    }

}

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.