Stripy42 Posted September 19, 2007 Share Posted September 19, 2007 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 Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted September 19, 2007 Share Posted September 19, 2007 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. Quote Link to comment Share on other sites More sharing options...
Stripy42 Posted September 19, 2007 Author Share Posted September 19, 2007 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.