| S | M | T | W | T | F | S |
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
The Easypeasy Database
Today I've been testing the Easypeasy database for my widget project.
I began by installing the data to MySQL. Very easy to do as the downloadable zip comes with a file you can import directly into MyAdmin.
With the database installed I used two scripts to look at the data in more detail. Firstly, one to establish the initial database connecion – it’s an idea to keep this file separate so you only have to write it once. Then, a second script that builds a form and processes the results.
Once I started to plot my results it quickly became apparent that although Latitude and Longitude is returned for each entry, the numbers are all rounded up. This puts W10 and SE13 on the same spot, so there's still a bit of work to do to figure out how to the x and y fields effect the results.
Here’s the code I wrote for the form:
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
Input Post Code:</br><input type="text" name="code" size="30">
<input type="submit" name="submit" value="submit">
</form>
<?php
//Connect to the database
include 'connect.php';
//If the form has been submitted then process the form
if (isset($_POST['code'])) {
//Grab the Postcode from the form
$postcode = $_POST['code'];
//Convert the Postcode to all uppercase
$postcode = strtoupper($postcode);
//Break the Postcode into two
list($outcode, $partTwo) = split(' ', $postcode);
//Pull out the relevant fields from our database
$query = "SELECT latitude,longitude FROM hwz_postcodes WHERE outcode= '$outcode'";
$result = mysql_query($query) or die('Query failed: '.mysql_error());
$line = mysql_fetch_array($result, MYSQL_ASSOC);
//Print Results
print $postcode.' : ';
print $line['latitude'];
print ',';
print $line['longitude'];
//We've finished with the database, so close the connection
mysql_close($conn);
}
?>