rckehoe Posted February 22, 2010 Share Posted February 22, 2010 I am going to loose my mind, I am running into an issue that has got me stumped... This is suppose to be a very easy thing to do, but for some reason cannot figure it out... Any help is appreciated. I have got small table in my database called "vendors"... Inside this table I only have about 2-3 records... Each of these records contains a latitude and longitude. Fields are called "lat" and "lon" I have a VERY simple mysql query like this: SELECT * FROM `vendors` WHERE (`lon` BETWEEN "-76.3066" AND "-133.5176") I have one specific record in the database that has a 'lon' of -104.884082.... In theory it should be pulling this record, but for some reason NO results are generated.... Have I gone off the deep end or something? I have tried everything I can possibly thing of with no luck!!! Someone please help me! Link to comment https://forums.phpfreaks.com/topic/192874-very-simple-mysql-problem/ Share on other sites More sharing options...
sader Posted February 22, 2010 Share Posted February 22, 2010 I think no results are returned cuz -76 > -133 when between operation wants get boundries likse so (`lon` BETWEEN min AND max) here's how the query should look: SELECT * FROM `vendors` WHERE (`lon` BETWEEN -133.5176 AND -76.3066 ) In php to avoid such problem build your query with min() max() functions $a = -133.5176; $b = -76.3066; $query = "SELECT * FROM `vendors` WHERE (`lon` BETWEEN ".min($a, $b)." AND ".max($a, $b)." )"; Link to comment https://forums.phpfreaks.com/topic/192874-very-simple-mysql-problem/#findComment-1016066 Share on other sites More sharing options...
rckehoe Posted February 22, 2010 Author Share Posted February 22, 2010 Well sock me sideways, it actually worked!!! I cannot tell you how much you have helped me out! THANK YOU SO MUCH! Link to comment https://forums.phpfreaks.com/topic/192874-very-simple-mysql-problem/#findComment-1016403 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.