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

 

 

 

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.

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.