Jump to content

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

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.