siamiam Posted July 9, 2009 Share Posted July 9, 2009 I'm trying to output: City Name, State Abbreviation I currently have the following code: $result = mysql_query("SELECT * FROM exp_weblog_data"); while($row = mysql_fetch_array($result)) { echo $row['field_id_10'] . ", " . $row['field_id_11']; echo "<br />"; } The above code works, partially. It produces the following: St. John's, NL New York, NY New York, NY New York, NY New York, NY Los Angeles, CA San Francisco, CA Los Angeles, CA I need assistance on how to remove the duplicates. I read information about using "array_unique" but I'm unsure of where to start using that function within the code I currently have. I would really appreciate it if someone could point me in the right direction. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/165415-solved-eliminate-duplicates-from-mysql-results/ Share on other sites More sharing options...
cunoodle2 Posted July 10, 2009 Share Posted July 10, 2009 Why are you selecting "*" if you are only using 2 columns? Try this.. SELECT DISTINCT city, state FROM exp_weblog_data; Something like that should get you going in the right direction. Also note that you will need to modify the above query with the actual column names (as apposed to "city" and "state" like I am using). Just replace those with whatever your column names are. Quote Link to comment https://forums.phpfreaks.com/topic/165415-solved-eliminate-duplicates-from-mysql-results/#findComment-872416 Share on other sites More sharing options...
siamiam Posted July 10, 2009 Author Share Posted July 10, 2009 aaah! Thanks so much! I wasn't familiar with 'DISTINCT' I guess I was overcomplicating it. Quote Link to comment https://forums.phpfreaks.com/topic/165415-solved-eliminate-duplicates-from-mysql-results/#findComment-872424 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.