Skip to content

Instantly share code, notes, and snippets.

@AtomicSmash
Last active December 24, 2015 19:49
Show Gist options
  • Save AtomicSmash/6853407 to your computer and use it in GitHub Desktop.
Save AtomicSmash/6853407 to your computer and use it in GitHub Desktop.
INCOMPLETE - So far this script grabs local authority information from openlylocal.com, then output the address and turn the postcode into an array.
<?php
$xml=simplexml_load_file("http://openlylocal.com/councils/all.xml");
echo "<pre>";
//print_r($xml);
echo "</pre>";
foreach($xml->council as $council){
//echo("COOL");
echo($council->address.",".$council->address."<br>");
//echo($council->address.",".$council->address."<br><br>");
$str = $council->address;
$words = explode(" ", $str);
//$firstWords = array_slice($words, 0,5);
$lastWords = array_slice($words, -2,2);
//print_r($firstWords);
print_r($lastWords);
echo("<br>First part of postcode to store: ".$lastWords[0]);
echo("<br><br>");
}
?>
<?php
echo date('h:i:s') . "\n";
// sleep for 10 seconds
sleep(10);
// wake up !
echo date('h:i:s') . "\n";
sleep(10);
?>
<?php
// Connects to your Database
set_time_limit(200000);
//mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("postcodes") or die(mysql_error());
$data = mysql_query("SELECT * FROM table")
or die(mysql_error());
//Print "<table border cellpadding=3>";
$words = "";
$lastWords = "";
while($info = mysql_fetch_array( $data ))
{
//Print "<tr>";
$words = explode(" ", $info['var1']);
//$firstWords = array_slice($words, 0,5);
$lastWords = array_slice($words, -2,2);
mysql_query("INSERT INTO finaloutput (full, first, last)
VALUES ('".$info['var1']."', '".$lastWords[0]."','".$lastWords[1]."')");
//Print "<th>Postcode:</th> <td>".$info['var1'] . "</td> ";
}
//Print "</table>";
echo "done";
?>
<?php
// Connects to your Database
set_time_limit(20000);
mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("postcodes") or die(mysql_error());
$data = mysql_query("SELECT * FROM my_table2")
or die(mysql_error());
//Print "<table border cellpadding=3>";
$words = "";
$lastWords = "";
while($info = mysql_fetch_array( $data ))
{
//Print "<tr>";
$words = explode(" ", $info['var1']);
//$firstWords = array_slice($words, 0,5);
$lastWords = array_slice($words, -2,2);
//mysql_query("INSERT INTO output2 (full, first, last)
//VALUES ('".$info['var1']."', '".$lastWords[0]."','".$lastWords[1]."')");
//Print "<th>Postcode:</th> <td>".$info['var1'] . "</td> ";
}
//Print "</table>";
echo "done";
?>
GET uniques
SELECT *
FROM output2
GROUP BY first
HAVING COUNT(DISTINCT first) = 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment