Author Topic: PHP MySQL and Unique Records  (Read 281 times)

0 Members and 1 Guest are viewing this topic.

Offline andyd34Topic starter

  • Enthusiast
  • Posts: 98
  • Gender: Male
    • View Profile
PHP MySQL and Unique Records
« on: July 03, 2009, 07:14:27 AM »
I have a MySQL database set up lik e this

Code: [Select]
id, INT, autoincrement, primary
country, varchar
region, varchar
city, varchar
p_codes varchar
[/php]

I want to select a unique town with a unique first part of post code but don't have the first idae how to do it, can anyone help please

Offline backie

  • Irregular
  • Posts: 33
    • View Profile
Re: PHP MySQL and Unique Records
« Reply #1 on: July 03, 2009, 07:20:46 AM »
SELECT * FROM Table WHERE p_codes REGEXP '^ML1 ';

Clearly change ML1 to whatever unique post code you have.


Offline andyd34Topic starter

  • Enthusiast
  • Posts: 98
  • Gender: Male
    • View Profile
Re: PHP MySQL and Unique Records
« Reply #2 on: July 03, 2009, 07:44:56 AM »
Sorry I was a bit vague in my question.

I want to return a list like this



echo $place['country'] . ', '.$place['county'].',  '$place['city'].' ('.substr($place['p_code'], 0, -3).')';



which would return

Quote
United Kindom, Greater London, Walford (E17)
United Kingdom, Lancashire, Wigan (WN1)
United Kingdom, Lancashire, Standish (WN4)
United Kingdom, Merseyside Liverpool (L1)
United Kingdom, Cheshire, Ellesmere Port {L63)
and so on

the are several recurrences of some city fields and I have to full post code for each street/road in the cities.

Hope this explains things a little more but thanks for you reply

Offline backie

  • Irregular
  • Posts: 33
    • View Profile
Re: PHP MySQL and Unique Records
« Reply #3 on: July 03, 2009, 07:59:46 AM »
Code: [Select]
SELECT DISTINCT country,county,city FROM Table

This will extract only on row for each count of Country Count and City

Code: [Select]
SELECT DISTINCT country,county,city,p_code FROM Table

May not be what you are wanting, will look and see if the full post code has been extracted before and return it if it hasn't

Hope this is more helpful