I have an array of the outcodes of UK postcodes - so LA12, LA13 etc.....
I also have a table of businesses, one of the columns being est_postcode - which has full UK postcodes - i.e - LA13 9UT etc.
so the variable $matches is created from the data stored in $postcode_radius - which works fine. (OUTCODES)
I then want to use the array to SELECT matching Postcodes from the businesses - but need to trim the last 3 characters from the est_postcode - i used the code below but nothing happens - i feel that the SUBSTRING part isnt correct - any advice??
$matches = implode(', ', array_unique($postcode_radius));
//echo $matches; // just checking that the variable looks right
$sql2 = "SELECT * FROM businesses WHERE SUBSTRING(est_postcode , -3) = '".$matches."'";
$result2 = mysql_query($sql2) or die('query failed: ' . mysql_error());
while ($row2 = mysql_fetch_array($result2, MYSQL_ASSOC))
{
echo $row2["est_postcode"], $row2["est_landline"];
}