Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more

Go Back   Webmaster Forums - Webmaster forum for HTML, PHP, ASP, CSS and more > Web Programming > PHP Development
User Name
Password

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 05-01-2006, 01:27 PM   #1 (permalink)
Loujohnson
Junior Member
 
Join Date: May 2006
Posts: 1
Default Database query problem to calculate distances

Have been trying to calculate distance using PHP/mysql between a current point and other places in England using national grid references, which is easy using Pythagorus. However I want the five nearest other places listed in the database (1000 other places total) in ascending order preferably using one call to the table. Each reference contains 9 digits, the first 4 are the length along the x axis from an imaginary 0,0 and the final 5 are the length along the y axis from the 0,0

The initial starting place is derived from data already called in a query held in ‘start_point’ :-


$x1 = substr($row['start_point'], 0, 4); // split out x axis coordinates
$y1 = substr($row['start_point'], 4, 5); // split out y axis coordinates

Have tried this but have got errors -

$query7 = "SELECT place_name, new_point FROM places ORDER BY sqrt(($x1-sustr(new_point,0,4)^2 + ($y1 – substr(new_point,4,5)^2) AS distance LIMIT 5”;

while ($row7 = mysql_fetch_array ($result7, MYSQL_ASSOC)) {

echo '<p>'. $row7['place_name'] . ' - '. $row7['x2'] .' - ' . $row7['distance'] .'</p>';

} // end of while loop

Am I doing too much in one query? I guess I am doing something wrong but would like to know why so I don’t do it again especially if it is particularly stupid!

Loujohnson is offline   Reply With Quote
Sponsored Links
Old 05-05-2006, 10:05 PM   #2 (permalink)
onetwosevendot
Junior Member
 
Join Date: May 2006
Posts: 1
Default Re: Database query problem to calculate distances

it could be that you have 'sustr(new_point,' instead of substr, but what is the actual error message?
onetwosevendot is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Points Per Thread View: 1.00
Points Per Thread: 11.00
Points Per Reply: 5.00



» Sponsors

» Links

» Affiliates
Web Hosting
Online Backup Reviews
Marketing Find
Merchant Select
SiteMap Builder
Host Compare
Dedicated Servers

» Links

» Sports Network
Paintball Forum
Football Forum
Hockey Forum
Golf Forum
Boxing Forum
Lacrosse Forum
Baseball Forum
SnowBoarding Forum
Soccer Forum
MMA Forum


All times are GMT -4. The time now is 04:45 PM.



LinkBacks Enabled by vBSEO 3.0.0 RC8
Webmaster Forums