Jump to content

Problem with MySQL query


kaneos

Recommended Posts

How can I get this query to work? I am having problems with the HAVING section of it.

 

 

SELECT id,price, ( 6371 * acos( cos( radians($lat) ) * cos( radians( lat ) )
  * cos( radians( lng ) - radians($lng) ) + sin( radians($lat) ) 
  * sin( radians( lat ) ) ) ) AS distance
FROM fuelstations
HAVING distance < 250 , price > 0
ORDER BY price LIMIT 0 , 60;

Link to comment
Share on other sites

I have actually worked worked that one out, I needed to use AND in the HAVING statement.  but this new one is giving me some problems.

 


<?php
include "connectionfile.php";

$userinput = $_GET["userinput"];

$listcitys = mysql_query("SELECT town, lat, lng  FROM postcode WHERE postcode=$userinput");
WHILE($lstctys = mysql_fetch_array($listcitys)) {
$town=$lstctys['town'];
$lat=$lstctys['lat'];
$long=$lstctys['lng'];


echo "<a href='search2.php?lat=$lat&lng=$long'>$town</a><br />";
}



?>


 

It seems that the $userinput variable is not registering with the query when it is a sting with letters however does work with when the postcode is entered (numbers)

 

any suggestions?

Link to comment
Share on other sites

Are you sending in a query parameter called "userinput"?  If you aren't then your script is looking for that (i.e. $_GET['userinput'] looks there).

 

Side Note: You should be careful and sanitize your input because someone could SQL inject you there.

 

~juddster

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.