我验证了两个邮政编码,然后运行两个mysql查询来获取每个邮政编码的邮政城市 那么邮政城市将与两个阵列进行比较,看看邮政城市是否是伦敦内城区,或者是伦敦郊区。 我的代码运行没有任何错误,但 放入in_array时无法将标志设置为1或0。 不输出任何东西。我知道我应该切换到mysqli或pdo。任何帮助将不胜感激。
$innerlondon = array('Bromley', 'Croydon', 'Dartford', 'East London', 'City of London', 'Enfield', 'Harrow', 'Ilford', 'Kingston-upon-Thames', 'North London', 'North West London', 'Romford', 'South East London', 'Sutton', 'South West London', 'Twickenham', 'Southall', 'West End', 'West Central');
$outterlondon = array('Aberdeen', 'Bath', 'Belfast', 'Birmingham', 'Blackburn', 'Blackpool', 'Bolton', 'Bournemouth', 'Bradford', 'Brighton', 'Bristol', 'Cambridge', 'Canterbury', 'Cardiff', 'Carlisle', 'Chelmsford', 'Chester', 'Colchester', 'Coventry', 'Crewe', 'Darlington', 'Derby', 'Doncaster', 'Dorchester', 'Dudley', 'Dumfries', 'Dundee', 'Durham', 'Exeter', 'Falkirk', 'Galashiels', 'Glasgow', 'Gloucester', 'Guernsey', 'Guildford', 'Halifax', 'Harrogate', 'Hebrides', 'Hemel Hempstead', 'Hereford', 'Huddersfield', 'Hull', 'Ipswich', 'Isle Of Man', 'Jersey', 'Kilmarnock', 'Kirkcaldy', 'Kirkwall', 'Lancaster', 'Leeds', 'Leicester', 'Lerwick', 'Lincoln', 'Liverpool', 'Llandrindod', 'Llandudno', 'lnverness', 'Luton', 'Manchester', 'Medway', 'Milton Keynes', 'Motherwell', 'Newcastle', 'Newport', 'Northampton', 'Norwich', 'Nottingham', 'Oldham', 'Oxford', 'Paisley', 'Perth', 'Peterborough', 'Plymouth', 'Portsmouth', 'Preston', 'Reading', 'Redhill', 'Salisbury', 'Sheffield', 'Shrewsbury', 'Slough', 'Southampton', 'Southend-on-Sea', 'St Albans', 'Stevenage', 'Stockport', 'Stoke-on-Trent', 'Sunderland', 'Swansea', 'Swindon', 'Taunton', 'Teesside', 'Telford', 'Tonbridge', 'Torquay', 'Truro', 'Wakefield', 'Walsall', 'Warrington', 'Watford', 'Wigan', 'Wolverhampton', 'Worcester', 'York');
$sql = "SELECT `town` FROM `ukpostcodes` WHERE `postcode`='$postcode1' LIMIT 1";
$result = mysql_query($sql, $con) or die(mysql_error());
$postal_town1 = mysql_fetch_assoc($result);
if(in_array($postal_town1, $innerlondon ))
{
echo "It is an inner London District = ";
echo $town1=$postal_town1['town'];
echo $inlondon=1; //set flag to 1
}
else
{
echo $inlondon=0; //set flag to 0
}
$sql = "SELECT `town` FROM `ukpostcodes` WHERE `postcode`='$postcode2' LIMIT 1";
$result = mysql_query($sql, $con) or die(mysql_error());
$postal_town2 = mysql_fetch_assoc($result);
if(in_array($postal_town2, $outterlondon ))
{
echo " It is an outter London District = ";
echo $town2=$postal_town2['town'];
echo $outlondon=1; //set flag to 1
}
else
{
echo $outlondon=0; //set flag to 0
}