kaneos Posted October 23, 2011 Share Posted October 23, 2011 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; Quote Link to comment https://forums.phpfreaks.com/topic/249628-problem-with-mysql-query/ Share on other sites More sharing options...
kaneos Posted October 23, 2011 Author Share Posted October 23, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/249628-problem-with-mysql-query/#findComment-1281515 Share on other sites More sharing options...
awjudd Posted October 23, 2011 Share Posted October 23, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/249628-problem-with-mysql-query/#findComment-1281521 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.