bigmax Posted December 1, 2006 Share Posted December 1, 2006 Good day guys. I'm a total beginner with PHP so I might naturally be missing out on some function that is obvious to those familiar with it. I have a problem -- have to remove duplicate strings from a MYSQL query output...don't know how, using PHP that is.So if the query displays something like:[code]JoeJoeJamesJaneMary MaryMaryJohn[/code]I need it to display only Joe, James, Jane, Mary, John, using the above analogy. Holy shit....how?? PHP's confusing...[code]<?/* MySQL connection script here...*//* connected. */$town = "Tumbaktu";$names = mysql_query("SELECT Name FROM my_table WHERE Town=$town");while($row = mysql_fetch_array($names, MYSQL_NUM)){ // using these two lines, i get an empty display $res = array_unique($row); print "<br>".$res[0]; /* whereas were i to write simplyprint "<BR>".$row[0]; instead, i'd get a list similar to the first one above... */}?>[/code]Kindly help anybody. Link to comment https://forums.phpfreaks.com/topic/29140-avoid-duplicate-strings-in-mysql-output/ Share on other sites More sharing options...
kenrbnsn Posted December 1, 2006 Share Posted December 1, 2006 You want to do something like the following:[code]<?php$town = "Tumbaktu";$q = "select distinct Name FROM my_table WHERE Town=$town");$names = mysql_query($q) or die("Problem with query: $q<br>" . mysql_error());while($row = mysql_fetch_assoc($names)){ echo $row['Name'] . '<br>';}?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/29140-avoid-duplicate-strings-in-mysql-output/#findComment-133593 Share on other sites More sharing options...
bigmax Posted December 1, 2006 Author Share Posted December 1, 2006 That does it, thank you Ken. :-) Link to comment https://forums.phpfreaks.com/topic/29140-avoid-duplicate-strings-in-mysql-output/#findComment-133602 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.