Jump to content

[SOLVED] identifying multiple results as one


MikeDXUNL

Recommended Posts

mysql table:

 

videogames

gameid | gamename

1            ffffff

2            gggg

3            hhhh

 

 

achievements

achid  | achname | gameid

1          secret        1

2          secret        1

3          destroy..      1

4          secret          2

5          something      2

6          thisname      3

 

 

 

right now I have

 

<?php

$get_achs = mysql_query("SELECT * FROM achievements WHERE achname = 'Secret'") or die(mysql_error());

?>

 

this will pick out the ach's with the name 'secret'

i will use those gameids (from the achievements table) to then search the videogames table and retrieve a game name

 

but I dont want the results of $get_achs to be

gameid: 1

gameid: 1

gameid: 2

 

gameid 1 has two secret achievements so the results will show up twice.

i only want gameid 1 to show up once.

 

Help is appreciated.

Mike

 

 

 

Link to comment
Share on other sites

Here is one option

 

<?php
$get_achs = mysql_query("SELECT gameid FROM achievements WHERE achname = 'Secret' GROUP BY gameid ORDER BY gameid") or die(mysql_error());
?>

 

Or in one query to fetch the game names directly.:

 

<?php
$get_achs = mysql_query("SELECT v.gamename, v.gameid FROM achievements a JOIN videogames v USING (gameid) WHERE a.achname = 'Secret' GROUP BY v.gamename, v.gameid ORDER BY v.gameid") or die(mysql_error());
?>

 

All untested unfortunately .. I do not have a mysql installation to test with.

Link to comment
Share on other sites

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.