Jump to content

[SOLVED] Trying To Stop Retrieving Duplicate Records


refiking

Recommended Posts

I have some records that are stored in my db twice because they have one entry field that's different.  For example. One user might be a part of 3 different "dregs" so they will have 3 separate records.  which looks something like this:

 

Uid(User ID)      Drid (Dreg Id)

1                    15

1                    28

1                    41

 

When I pull a query asking for the users in 5 dregs (3 of which are the ones included here), it returns this user 3 times.  How can I get it to only retrieve this user once and discard the duplicates?  Here is the code snippet:

 

$sql2 = mysql_query("SELECT * FROM downer WHERE lid = '$lgs' ORDER BY drid");
while ($row2 = mysql_fetch_assoc($sql2)){
$drid = $row2['drid'];
$sql3 = mysql_query("SELECT * FROM dregusers WHERE drid = '{$row2['drid']}'");
while ($row3 = mysql_fetch_assoc($sql3)){
echo '<option><font color="black">'.$row3['username'].'</font></option>';

Here is the code I changed it to:

$sql3 = mysql_query("SELECT * FROM dregusers WHERE drid IN (SELECT * FROM downer WHERE lid = '$lgs') GROUP BY uid");

 

Here is what the script returned:

 

Parse error: syntax error, unexpected '}' on line 28

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.