UK Database Functions

UK Database

We have compiled some PHP functions to make using our database as easy as possible. Some knowledge of PHP, MySQL & HTML is needed but we have done a lot of the hard work for you already.

Please see the list below for examples of how the database information can be used.
All the code on this page is retrieved from the database using the functions shown and they are all included with our UK database package.
The data in the database can be easily updated from the database admin page (also included in the database package).

You can see the database in action at: http://www.quotemeremovals.co.uk/

back to main UK database page

 


Function: Show all Counties

PHP function name: getAllCounties()
Returns an array of all UK counties in alphabetical order.
Example:
Fill in a SELECT item for a form:


Function: Show all UK Towns

PHP function name: getTownsList()
Returns an array of all UK towns in alphabetical order.
Example:
Fill in a SELECT item for a form:


Function: Show all postcode areas in a town

PHP function name: getPostcodesFromCity($city)
Returns an array of all postcodes in a town.
Example:
Fill in a SELECT item for a form with postcodes in the Manchester area:
getPostcodesFromCity('Manchester')

As you can see in the above example, postcodes aren't sorted numerically. Most websites display postcodes this way but I find it's better to sort them numerically using the following function.


Function: Sort a postcode list numerically

PHP function name: sortPostcodeArray($array)
Returns an array of all postcodes in a town & sorted numerically.
Example:
Fill in a SELECT item for a form with postcodes in the Manchester area & sort them numerically:


Function: Show towns in a county

PHP function name: getTownsInCounty($county)
Returns an array of all towns within a county.
Example:
Fill in a SELECT item for a form with town names within East Sussex:
getTownsInCounty('East Sussex')


Function: Show all UK postcode areas

PHP function name: getPostCodeAreas()
Returns an array of all postcode areas (postcode areas without numbers, eg BN).
Example:
Fill in a SELECT item for a form with postcode areas:


Function: Get the postcode area for a town

PHP function name: getAreaFromTown($town)
Returns a string of the postcode area (postcode without numbers, eg BN).
Example:
What is the postode area of Brighton?:
getAreaFromTown('Brighton')
The Brighton postcode area is: BN


Function: Get the county for a town

PHP function name: getCountyFromTown($town)
Returns a string of the county for a town.
Example:
What county is Torquay in?:
getCountyFromTown('Torquay')
Torquay is in the county: Devon


Function: Get the first postcode for a postcode area

PHP function name: getFirstPostcode($area)
Returns a string of the first postcode.
Example:
What is the first postode in the BN area?:
getFirstPostcode('BN')
The first BN postcode area is: BN1


Function: Get the first postcode for a town

PHP function name: getFirstPostcodeFromTown($town)
Returns a string of the first postcode.
Example:
What is the first postode in Southampton?:
getFirstPostcodeFromTown('Southampton')
The first Southampton postcode area is: SO14


Function: Get the town name from a postcode

PHP function name: getCity($zip)
Returns a string of the town.
Example:
What town is the postcode CV5 in?:
getCity('CV5')
CV5 is in: Coventry


Function: Calculate approx. distance between 2 postcodes

PHP function name: calc_distance($pcodeA,$pcodeB)
Returns the number of miles between 2 postcodes.
Example:
What is the distance between IP5 & BN8?:
calc_distance('IP5','BN8')
Distance between IP5 (Ipswich) & BN8 (Lewes): 116 miles
Covert to KM with the convertMilesToKm($miles) function: 187 km


Function: Show postcodes within a radius of a postcode

PHP function name: getPCinRange($postcode,$radius,$ireland)
Returns an array of all postcodes within a set radius of a postcode.
note: The $ireland variable is a boolean that, if true, will also include postcodes in Northern Ireland (if in range).
Example:
Fill in a SELECT item for a form with postcodes within 20 miles of BN3:
getPCinRange('BN3',20,false)


Function: Get Latitude & Longitude of a postcode

PHP function names: getLatitude($pc) & getLongitude($pc)
Returns the latitude & longitude coordinates of a postcode.
Example:
What is the latitude & longitude of BN8?:
getLatitude('BN8') and getLongitude('BN8')
The latitude & longitude of BN8 is: 50.908°N , 0.081°E


Function: Get the population for a town

PHP function name: getPopulation($town)
Returns a string of the population of a town.
Example:
What is the population of Lincoln?:
getPopulation('Lincoln')
The population of Lincoln is: 85,595 (2001)


Function: Get Wikipedia data for a town

PHP function names: getWikiLink($town), getWikiText($town)
Returns a string of the Wikipedia URL & town info text.
Example:
What is the Wikipedia link for Brighton?:
getWikiLink('Brighton')
The Wikipedia link for Brighton is: http://en.wikipedia.org/wiki/Brighton

Wiki text for Brighton:
getWikiText('Brighton')

Brighton is a town in the city of Brighton and Hove (formed from the towns of Brighton, Hove, Portslade and several other areas) in East Sussex on the south coast. For administrative purposes, Brighton and Hove is not part of the non-metropolitan county of East Sussex, but remains part of the ceremonial county of East Sussex. Modern Brighton forms part of a conurbation stretching along the coast, with a population of around 480,000.

Eight million tourists a year visit Brighton. The town also has a substantial business conference industry. Brighton Pier (originally and in full "The Brighton Marine Palace and Pier", and for long known as the Palace Pier) opened in 1899. It features a funfair, restaurants and arcade halls.

Created in 1883, Volk's Electric Railway runs along the inland edge of the beach from Brighton Pier to Black Rock and Brighton Marina. It is the world's oldest operating electric railway.

The seafront has bars, restaurants, nightclubs and amusement arcades, principally between the piers. Being less than an hour from London by train has made the city a popular destination. Brighton beach has a nudist area (south of the easterly part of Kemptown). Brighton's beach, which is a sand-free shingle beach, although it is sand when going into the sea, has been awarded a blue flag. The Monarch's Way long-distance footpath heads west along the seafront above the beach.

* Information from Wikipedia is reproduced under the Creative Commons Deed.


Function: Get phone dialling codes for a town

PHP function name: getDialCode($town)
Returns a string of the dialling code of a town.
Example:
What is the phone dial code for Abingdon?:
getDialCode('Abingdon')
The phone dial code for Abingdon is: 01235


MySQL UK Database

 

You can see the database in action at: http://www.quotemeremovals.co.uk/

back to main UK database page