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? Quote Link to comment 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. Quote Link to comment 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.. Quote Link to comment 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? Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Jack.Straw Posted November 18, 2006 Author Share Posted November 18, 2006 awesome, thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.