Jack.Straw Posted November 11, 2006 Share Posted November 11, 2006 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 More sharing options...
AndyB Posted November 11, 2006 Share Posted November 11, 2006 [quote author=Jack.Straw link=topic=114650.msg466539#msg466539 date=1163268683]$row[PhoneNumber] doesn't get filled. Can anyone help me understand why?[/quote]Because you specifically only retrieved Name from the database table. Link to comment https://forums.phpfreaks.com/topic/26943-need-help-with-distinct/#findComment-123228 Share on other sites More sharing options...
Jack.Straw Posted November 15, 2006 Author Share Posted November 15, 2006 Can i specify more than 2 without both of them getting distinct applied? I want to display phone numbers from rows that have distinct names.. Link to comment https://forums.phpfreaks.com/topic/26943-need-help-with-distinct/#findComment-125077 Share on other sites More sharing options...
fenway Posted November 15, 2006 Share Posted November 15, 2006 [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? Link to comment https://forums.phpfreaks.com/topic/26943-need-help-with-distinct/#findComment-125121 Share on other sites More sharing options...
Jack.Straw Posted November 15, 2006 Author Share Posted November 15, 2006 Ok, say the database looks like this:[u]Name[/u] - [u]Phone[/u]Joe - 333-3333Dan - 444-4444Bill - 444-4444Joe - 666-6666Tom - 777-7777I want it to pick out distinct names and display the phone numers. It would fill the array with:Joe - 333-3333Dan - 444-4444Bill - 444-4444Tom - 777-7777 Link to comment https://forums.phpfreaks.com/topic/26943-need-help-with-distinct/#findComment-125272 Share on other sites More sharing options...
fenway Posted November 16, 2006 Share Posted November 16, 2006 OK -- but how did you decide one phone number over the other? Or do you not care? Link to comment https://forums.phpfreaks.com/topic/26943-need-help-with-distinct/#findComment-125619 Share on other sites More sharing options...
Jack.Straw Posted November 17, 2006 Author Share Posted November 17, 2006 It wouldn't matter to me which number by joe that i was returned. This is actually just a meaninglyess example - the actual use is much much more complex and hard to explain. Link to comment https://forums.phpfreaks.com/topic/26943-need-help-with-distinct/#findComment-125879 Share on other sites More sharing options...
fenway Posted November 17, 2006 Share Posted November 17, 2006 Well, if you don't care which one, then just GROUP BY name. Link to comment https://forums.phpfreaks.com/topic/26943-need-help-with-distinct/#findComment-125933 Share on other sites More sharing options...
Jack.Straw Posted November 17, 2006 Author Share Posted November 17, 2006 But GROUP BY won't only return rows with distinct names, will it? Link to comment https://forums.phpfreaks.com/topic/26943-need-help-with-distinct/#findComment-126171 Share on other sites More sharing options...
fenway Posted November 17, 2006 Share Posted November 17, 2006 [quote author=Jack.Straw link=topic=114650.msg469595#msg469595 date=1163778925]But GROUP BY won't only return rows with distinct names, will it?[/quote]It will return one row per name. Link to comment https://forums.phpfreaks.com/topic/26943-need-help-with-distinct/#findComment-126393 Share on other sites More sharing options...
Jack.Straw Posted November 18, 2006 Author Share Posted November 18, 2006 awesome, thank you! Link to comment https://forums.phpfreaks.com/topic/26943-need-help-with-distinct/#findComment-126478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.