Im doing a postcode search script, which is very ambitious for my level of skill. I have it working in a very very messy way, so am looking for advice on how to tidy it up.
Currently somebody types in a postcode/zipcode and a radius. It returns all the postcodes within the radius. Now i want to query the table for partial matches of the returned postcodes to find all records that are within the radius.
Is this the best way? Its the only way i can think of.
The other problem is my database has 6-7 digit postcodes, but the postcode database only does the area section (which is good enough for my needs) this is the reason i put the % wildcard at the end of the returned postcodes.
now, although i would never use the following in a commerical suituation I did it like this to test it would work, im fully aware of the code being shameful!
// the first bit of script is fine, it returns the array "finalResult"
if(is_array($finalResult)){
foreach($finalResult as $location){
$item[] =$location['Pcode']."%";
}
}
$sql_5 = "select * from idx_link where postcode LIKE '$item[0]' or postcode like '$item[1]' or postcode like '$item[2]'
$sitesfound = doQueryResult($sql_5);
I cut Sql_5 down for posting, it carries on with the or postcode like '$item[??]' as i can have up to 50 postcodes returned. This is what im not happy with. Any suggestions ? I would really like it to be automatically generated with the right numner of sql statments... or even do it a completly different way?
thanks 🙂