Jump to content

IF's and Postcodes


Stripy42

Recommended Posts

Hello,

I'm making a bit of code that chooses postage cost according to the post code.

I've got code that checks if it is valid, then code that splits it up into four parts.

 

$firstl $firstn $secondn $secondl

 

now the problem is that one of the post codes groups required is LE (all except 16.8, 16.9)

That means if

$firstl == LE

then it is ok unless

$firstn == 16

and

$second == 8 or 9

 

So I've been using things like

($firstl=="BE" && $firstn==12 && $secondn==7) //to see if ih has to be LE 12.7
($firstl=="TN" && $firstn>=19 && $firstn<=22) //for things like TN 19 to 22
$firstl=="RH" // for all RH's

But I can't figure out a way off doing "all except ..."

 

Any help would be great thanks

 

 

Link to comment
https://forums.phpfreaks.com/topic/69903-ifs-and-postcodes/
Share on other sites

There are program out there to do Zip code Calculations (Using cURL and USPS.com or some other shipping site)  however if you are looking for your own I suggest you make an array/table of the Zipcode's shipping cost based on the first 3 digits of the zip code (Since the last two are meaningless in the terms of shipping).  That gives you just over 1000 entries to do, but then all you have to do is say

$cost = $shipping_array[$firstthreeofzip];  and you can get the first 3 of the zip code via string mainiuplation of the zipcode after its validness is proven.

 

$shipping_array could be gathered from mysql/stored there so that you can update it faster/use on a lot of different applications without being stuck in a static array.

Link to comment
https://forums.phpfreaks.com/topic/69903-ifs-and-postcodes/#findComment-351088
Share on other sites

In the UK the second but of the postcode does need the end numbers sometimes, I think it's when they ran out of numbers.

 

Anyway arrays, I thought I might need them, still haven't quite figured them out yet. I'm going to stick to the IF method for now.

And I've found out I do need all of the LE's

 

But just for interest how would I do it, this doesn't work;

if ($firstl=="BE" && !($firstn==16 && $secondn==) {
// do stuff
}

 

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/69903-ifs-and-postcodes/#findComment-351115
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.