Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

Function within query statement?

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

Postby Hurkle » Wed Feb 05, 2003 1:50 pm

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 = 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]
New php-forum User
New php-forum User
Posts: 36
Joined: Tue Jan 07, 2003 8:45 am
Location: Minnesota, USA

Return to PHP coding => General

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.