Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5845825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:29:24+00:00 2026-05-22T12:29:24+00:00

I must first let you know that while I am an experienced rails developer,

  • 0

I must first let you know that while I am an experienced rails developer, I am quite rusty at PHP and raw SQL. I am attempting to build a store finder app using this tutorial and this tutorial. I am meeting

This is the code I am using for my query (with my own database column names)

$user_lat = $_GET["lat"];
$user_lng = $_GET["lng"];
$radius = $_GET["radius"];

$query = "SELECT 'Address','LocName','Latitude','Longitude', ( 3959 * acos( cos( radians($user_lat) ) * cos( radians( Latitude ) ) * cos( radians( Longitude ) - radians($user_lng) ) + sin( radians($user_lat) ) * sin( radians( Latitude ) ) ) ) AS distance FROM Locations ORDER BY distance";

And I am returning the results with this (just as a test):

$result = mysql_query($query);
if (!$result) {
  die("Invalid query: " . mysql_error());
}

$num=mysql_numrows($result);

mysql_close();
?>
<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Distance</font></th>
<th><font face="Arial, Helvetica, sans-serif">Address</font></th>
</tr>

<?php
while ($row = mysql_fetch_assoc($result)) {
$f1=mysql_result($result,$i,"LocName");
$f2=mysql_result($result,$i,"distance");
$f3=mysql_result($result,$i,"Address");
?>

<tr>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f2 ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font></td>
</tr>

<?php
$i++;
}
?>

However I am getting the following results when i got go: findstore.php?lat=33.98&lng=-118.42

Name    Distance    Address
LocName     0.65415504532801    Address
LocName     0.65415504532801    Address
LocName     0.666819627384179   Address
LocName     0.923277344110443   Address
LocName     2.32751232712236    Address
LocName     2.33924574433009    Address

etc.

obviously the Distance is calculating properly but I am having trouble getting the Address and Location Name for each.

What am I doing wrong?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T12:29:25+00:00Added an answer on May 22, 2026 at 12:29 pm

    Try replacing the single quotes in your query with backticks.

    i.e.:

    $query = "SELECT `Address`,`LocName`,`Latitude`,`Longitude`, ( 3959 * acos( cos( radians($user_lat) ) * cos( radians( Latitude ) ) * cos( radians( Longitude ) - radians($user_lng) ) + sin( radians($user_lat) ) * sin( radians( Latitude ) ) ) ) AS distance FROM Locations ORDER BY distance";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all, I must say that I am quite new to the API
My colleague here argues that new programmers must learn ASP first, before they learn
I first got an error usign the code below, explaining that DataGridLinkButton' must be
I'm trying out my first Spring project and must be doing something really stupid
First thing: must be done entirely in javascript. (JQuery/mootools optional) I have a series
First, a little background. I have two ASP.NET web applications that use SQLServer session
I'm working on my first web site that requires SSL, it's hosted on a
There must be a generic way to transform some hierachical XML such as: <element1
I must implement a web service which expose a list of values (integers, custom
I must be getting daft, but I can't seem to find how to read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.