I should of mentioned that you will need some kind of script(pdp/perl) or programme(C++/VB/Delphi) the example below is for php, although I will be porting it to Delphi. Look at my previous post for explaination.
<?php
foreach ($_POST as $key => $value) {$$key = $value;}
foreach ($_GET as $key => $value) {$$key = $value;}
include('pageconnect.php');
$connection = @mysql_connect($host, $user, $pass) or die ("Unable to connect to database"

;
mysql_select_db($db) or die ("Unable to select database: $db "

;
for ($i = strlen($callno); $i != 0; $i--) {
$areacode = substr($callno, 0,$i);
$query = "SELECT *
FROM stdcodes
WHERE areacode = '$areacode' ";
$queryResult = mysql_query($query);
$numrows =mysql_num_rows($queryResult);
if($numrows >0) {
break;
}
}
$query = "SELECT *
FROM stdcodes
WHERE areacode = '$areacode' ";
$queryResult = mysql_query($query);
if ($queryResult) {
while($row =mysql_Fetch_array($queryResult)) {
echo "the country for $row[areacode] is $row[country]" ;
}
} else {
echo "Query failed. SQL=$selectresult error=".mysql_error();
}
?>