testing areacodes within a given radius
Posted: Thu Feb 05, 2004 5:42 am
Hi I have been designing a site along the lines of upmystreet.com which finds amenities in the locality of the user based on the areacode .
I have 2 database tables.
1. has areacodes mapped to GPS grid refs
2. is fed from a form which users fillout and includes areacode
I approached it in php as follows
a. test the user areacode and format it so it matchs the db at 1.
b. search the 1 db for matches within a given radius achieved by adding half required radius distance to the grid ref on all 4 compass points.
---------------------------------------------------------------------------------
SELECT* FROM postcodes WHERE x>=$s_vertical AND x<=$n_vertical AND y>=$e_horizontal AND y<=$w_horizontal
-----------------------------------------------------------------------------------
c. this is where it gets sticky. results go to db.2 to test each one against a corresponding field in another table
================================================== ==
$result = mysql_query ("SELECT* FROM areacodes");
if ($myrow = mysql_fetch_array ($result)) {
do {
sprintf ($myrow["areacode"]);
} while ($myrow = mysql_fetch_array($result));
}
$myrow = $areacodearray[0];
print $areacodearray[0];
=============================================
Above code doesn't work? What is the best way to approach this?
I have to get back a varying number of rows. If they are in the form of an array containing a single variable string I need to delimit it and then send each one individually through some kind of loop
or is it better to make a loop which returns a number of variables?
What is the best way to format the results and keep them in the php ?
d. which checks how many matches there are for each individual areacode and prints out the results to a browser.
I have 2 database tables.
1. has areacodes mapped to GPS grid refs
2. is fed from a form which users fillout and includes areacode
I approached it in php as follows
a. test the user areacode and format it so it matchs the db at 1.
b. search the 1 db for matches within a given radius achieved by adding half required radius distance to the grid ref on all 4 compass points.
---------------------------------------------------------------------------------
SELECT* FROM postcodes WHERE x>=$s_vertical AND x<=$n_vertical AND y>=$e_horizontal AND y<=$w_horizontal
-----------------------------------------------------------------------------------
c. this is where it gets sticky. results go to db.2 to test each one against a corresponding field in another table
================================================== ==
$result = mysql_query ("SELECT* FROM areacodes");
if ($myrow = mysql_fetch_array ($result)) {
do {
sprintf ($myrow["areacode"]);
} while ($myrow = mysql_fetch_array($result));
}
$myrow = $areacodearray[0];
print $areacodearray[0];
=============================================
Above code doesn't work? What is the best way to approach this?
I have to get back a varying number of rows. If they are in the form of an array containing a single variable string I need to delimit it and then send each one individually through some kind of loop
or is it better to make a loop which returns a number of variables?
What is the best way to format the results and keep them in the php ?
d. which checks how many matches there are for each individual areacode and prints out the results to a browser.