I don't know how to do exactly what you described, but here's an idea for you.
If you have a function that can calculate the distance between 2 zips, then you must have some way of getting positional data for a particular zip. I would add 2 columns to your zip code table, i.e. fld_zip_x, fld_zip_y. Write a script to calculate the x and y locations for each zip, and store that in the table. Then when it's time to build your query, your just doing a simple math operaration, rather than calling a custom function.
It sounds like you're going to have to do a join of some kind as well..
$str_sql = "select tbl_users.* FROM tbl_users LEFT JOIN tbl_zips ON tbl_users.zip = tbl_zips.zip WHERE (tbl_zips.fld_zip_x - " . $user_zip_x . "< ' " . $within . " ' ) AND (tbl_zips.fld_zip_y - " . $user_zip_y . "< ' " . $within . " ' ) "
that should get you started. You might have to figure out how to get the absolute value of the difference, or build your query so that the difference for x and y is > -1000 and less than +1000.
hope this helps.[/code]