Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.