Jump to content

Need help with DISTINCT


Jack.Straw

Recommended Posts

Hello.  How can i make the following statement fill the $row array with the PhoneNumer colum (which exists in the Friends table) as well? 

[code]
$result=mysql_query("SELECT DISTINCT Name FROM Friends WHERE Catagory='Female' ORDER BY Name ASC ");
while ($row=mysql_fetch_array($result))
  {
  echo $row[Name]." - ".$row[PhoneNumber];
  }
[/code]

$row[PhoneNumber] doesn't get filled. Can anyone help me understand why?
Link to comment
https://forums.phpfreaks.com/topic/26943-need-help-with-distinct/
Share on other sites

[quote author=Jack.Straw link=topic=114650.msg468468#msg468468 date=1163615618]
I want to display phone numbers from rows that have distinct names..
[/quote]
I'm not sure I know what you mean by this... which phone number would you show if there were 3 matching rows?
Ok, say the database looks like this:
[u]Name[/u] - [u]Phone[/u]
Joe - 333-3333
Dan - 444-4444
Bill - 444-4444
Joe - 666-6666
Tom - 777-7777

I want it to pick out distinct names and display the phone numers.  It would fill the array with:
Joe - 333-3333
Dan - 444-4444
Bill - 444-4444
Tom - 777-7777

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.