Jump to content

[SOLVED] Eliminate Duplicates from MySQL Results


siamiam

Recommended Posts

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!

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.

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.