Page 1 of 1

testing areacodes within a given radius

Posted: Thu Feb 05, 2004 5:42 am
by memepool
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.

Posted: Thu Feb 05, 2004 6:37 am
by jason
Okay, maybe I am missing something, but where are you assigned $areacodearray[0], and what the heck is the sprintf() for?

Posted: Thu Feb 05, 2004 7:21 am
by memepool
if ($result) {
do {
sprintf ($myrow["areacode"]);
} while ($myrow = mysql_fetch_array($result));

}

$row = $myrow["areacode"];


print $row;

what I am trying to do is get the values from the database an keep them inside a php page in order to put each row individually through a further process . SPRINTF does the same as printf but doesn't print out to the browser.

Can you think of a better way?

-------------------------------------------------------------------------------------
$sql = "SELECT * FROM $table
WHERE postcode LIKE '$postcode%' AND account = 1 ORDER BY name LIMIT
$start,$amount";

$result = mysql_query($sql);

$num_rows = mysql_num_rows($result);

//pulls out rows limited to 10 per page

$sql = "SELECT * FROM $table
WHERE postcode LIKE '$postcode%' AND account = 1 ORDER BY name";

$countresult = mysql_query($sql);

$record_count = mysql_num_rows($countresult);

return $num_rows;

// pulls out total number of rows
}
$counter = 0;

$postcode2 = $postcode;
$memorypostcode = $postcode;

//triplicates postcode variable

while($counter < $try)
{
$num_rows = findpostcode($postcode);
if($num_rows != 0)
{
break;
}
else
{
$letters = ereg_replace ("[^a-zA-Z]","",$postcode);
$numbers = ereg_replace ("[^0-9]","",$postcode);
$numbers++;
$postcode = $letters . $numbers;
}
$counter++;
}

if($num_rows == 0)
{
$letters = ereg_replace ("[^a-zA-Z]","",$postcode2);
$numbers = ereg_replace ("[^0-9]","",$postcode2);
$counter = 0;
while($numbers > 0)
{
$numbers--;
$postcode2 = $letters . $numbers;
$num_rows = findpostcode($postcode2);
if($num_rows != 0)
{
break;
}
if($counter > $try)
{
break;
}
$counter++;
}

}

if($record_count != 1)
{
$s = "s";
}



echo("Found $record_count record$s");
------------------------------------------------------------------------------------