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
https://forums.phpfreaks.com/topic/249628-problem-with-mysql-query/
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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.