News:

Tekforums.net - The improved home of Tekforums! :D

Main Menu

Postcode Radius Search thingy

Started by addictweb, July 11, 2006, 14:47:42 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

cornet

You want

$res_count = mysql_num_rows($result);


mysql_numrows() is part of the MySQL Improved Extension library.

Cornet

addictweb

Lol, mysql_num_rows was the only part I was sure of!

Thanks for the ongoing help. Its very much appriciated.
Formerly sexytw

addictweb

In the SQL statement that I am using (reminder: )

SELECT * , 3963 *2 * ASIN(
POW( POW( SIN( (
business.lat - postcodes.lat
) /2 ) , 2 ) + ( COS( postcodes.lat ) * COS( business.lat ) * POW( SIN( (
business.lon - postcodes.lon
) /2 ) , 2 ) ) , 0.5 )
) AS D
FROM business, postcodes
WHERE postcodes.PCode = $pcode
AND 3970 *2 * ASIN(
POW( POW( SIN( (
business.lat - postcodes.lat
) /2 ) , 2 ) + ( COS( postcodes.lat ) * COS( business.lat ) * POW( SIN( (
business.lon - postcodes.lon
) /2 ) , 2 ) ) , 0.5 )
) <= $distance
ORDER BY D
LIMIT 0 , 30

How do I select the value of D (representing the distance to the item) once the query has been executed?  I have tried:

   $row = mysql_fetch_row($result);
    $D=$row[D];

To no avail, I also need to do this to pin down why the statement doesnt return any values unless the radius distance is set to 10000 miles of so. :-S

Formerly sexytw

cornet

Quote from: sexytwIn the SQL statement that I am using (reminder: )

SELECT * , 3963 *2 * ASIN(
POW( POW( SIN( (
business.lat - postcodes.lat
) /2 ) , 2 ) + ( COS( postcodes.lat ) * COS( business.lat ) * POW( SIN( (
business.lon - postcodes.lon
) /2 ) , 2 ) ) , 0.5 )
) AS D
FROM business, postcodes
WHERE postcodes.PCode = $pcode
AND 3970 *2 * ASIN(
POW( POW( SIN( (
business.lat - postcodes.lat
) /2 ) , 2 ) + ( COS( postcodes.lat ) * COS( business.lat ) * POW( SIN( (
business.lon - postcodes.lon
) /2 ) , 2 ) ) , 0.5 )
) <= $distance
ORDER BY D
LIMIT 0 , 30

How do I select the value of D (representing the distance to the item) once the query has been executed?  I have tried:

   $row = mysql_fetch_row($result);
    $D=$row[D];

To no avail, I also need to do this to pin down why the statement doesnt return any values unless the radius distance is set to 10000 miles of so. :-S


Not to be one of those annoying *nix types that tell you to rtfm all the time but please do so every so often ;)

http://uk.php.net/mysql_fetch_row

What you actually want is
http://uk.php.net/manual/en/function.mysql-fetch-assoc.php

Cornet