SELECT DISTINCT..... but not quite as simple as that!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

SELECT DISTINCT..... but not quite as simple as that!

Post by simonmlewis »

Code: Select all

$result = mysql_query ("
SELECT * FROM matterusersrights 
INNER JOIN matterdata ON matterdata.clientcode = matterusersrights.clientcode 
WHERE matterusersrights.userid = $cookieid");
while ($row = mysql_fetch_object($result)) 
{
echo "<img src='images/icon_arrow.gif' />$row->persondealing<br/>";
}
    mysql_free_result($result);
    mysql_close($sqlconn);
I need to produce $row->persondealing as a Distinct value, as there will be more than one entry of any name.

Everything in the mysql_query is essential.
Anyone know how to get this to be a distinct result?

Simon
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: SELECT DISTINCT..... but not quite as simple as that!

Post by VladSun »

I'm not sure but it seems you need a GROUP BY user_id.
There are 10 types of people in this world, those who understand binary and those who don't
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: SELECT DISTINCT..... but not quite as simple as that!

Post by simonmlewis »

Perfect - and I cannot believe I didn't think of it.

Many thanks for the quick and perfect resolution!
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply