PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have a "search by zipcode" form. when a visitor types in a zip code, it gets the range of 100 higher and 100 lower. Everything works good except when i use a zipcode with a zero in front.
$wildcard = 01423;
$a = sprintf('%05d', ($wildcard - 100));
$b = sprintf('%05d', ($wildcard + 100));
//Getting
$c_query="SELECT * FROM user
WHERE zip
BETWEEN '$a' AND '$b'
ORDER by city ASC";
The problem is that PHP strips off zeros from the beginning of numbers. You could store $wildcard as a string, get the length, then tack on an opening zero if the length isn't the same after the math.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.