adzie Posted May 1, 2009 Share Posted May 1, 2009 Hello folks, I get no results returned even though I have a record that fits the criteria. I even tried removing the 0 from the longitude but get no result and I think its to do with the minue figure, Can anyone help? EGKK London Gatwick 51.148 -.1903 SELECT * from airports where Latitude >= '51.108676' and Latitude <= '51.208676' and Longitude >= '-0.223841' and Longitude <= '-0.123841' Quote Link to comment https://forums.phpfreaks.com/topic/156381-solved-search-between-two-values/ Share on other sites More sharing options...
Linda_swe Posted May 1, 2009 Share Posted May 1, 2009 Hi I think you can use the explicit command BETWEEN in the sql query. SELECT * from airports where Latitude BETWEEN '51.108676' AND '51.208676' AND Longitude BETWEEN '0.223841' AND -0.123841 Quote Link to comment https://forums.phpfreaks.com/topic/156381-solved-search-between-two-values/#findComment-823329 Share on other sites More sharing options...
kickstart Posted May 1, 2009 Share Posted May 1, 2009 Hi Are the longitudes and latitudes stored as numeric or character fields? All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/156381-solved-search-between-two-values/#findComment-823354 Share on other sites More sharing options...
adzie Posted May 1, 2009 Author Share Posted May 1, 2009 ok some testing and some result without the ' ' either side of the logitude I get the result SELECT * from airports where Latitude BETWEEN 52.9803 AND 53.0803 AND Longitude BETWEEN -0.5334 AND -0.4334 however when I put it into my php $query = "SELECT * FROM airports where Latitude BETWEEN '$AirportInfo[maxlat]' AND '$AirportInfo[minlat]' AND Longitude BETWEEN '$AirportInfo[maxlon]' AND '$AirportInfo[minlon]'"; withtout the ' ' around the values it wont return an value, however take away the ' ' and it returns an error Quote Link to comment https://forums.phpfreaks.com/topic/156381-solved-search-between-two-values/#findComment-823376 Share on other sites More sharing options...
adzie Posted May 1, 2009 Author Share Posted May 1, 2009 sorry i meant $query = "SELECT * FROM airports where Latitude BETWEEN '$AirportInfo[maxlat]' AND '$AirportInfo[minlat]' AND Longitude BETWEEN $AirportInfo['maxlon'] AND '$AirportInfo[minlon]'"; Quote Link to comment https://forums.phpfreaks.com/topic/156381-solved-search-between-two-values/#findComment-823382 Share on other sites More sharing options...
Linda_swe Posted May 1, 2009 Share Posted May 1, 2009 sorry i meant $query = "SELECT * FROM airports where Latitude BETWEEN '$AirportInfo[maxlat]' AND '$AirportInfo[minlat]' AND Longitude BETWEEN $AirportInfo['maxlon'] AND '$AirportInfo[minlon]'"; A bit confussing becuase in this one you have used $AirportInfo['maxlon'] and '$AirportInfo[minlon]' Anyway,the first one should work..i just did a quick example where my table is named poang. Can you echo the arrays and see if it contains the correct values ? <?php mysql_connect("whatever", "whatever", "") or die(mysql_error()); mysql_select_db("whatever") or die(mysql_error()); $airport['LongMin'] = "0.5"; $airport['LongMax'] = "1"; $airport['Lat'] = "5"; $query = "SELECT * FROM poang where poang BETWEEN '$airport[LongMin]' AND '$airport[LongMax]' AND modell BETWEEN '$airport[Lat]' AND '$airport[Lat]'"; $result = mysql_query($query); while ($rowFinder = mysql_fetch_assoc($result)) { echo $rowFinder['poang']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/156381-solved-search-between-two-values/#findComment-823394 Share on other sites More sharing options...
kickstart Posted May 1, 2009 Share Posted May 1, 2009 Hi Try:- $query = "SELECT * FROM airports where Latitude BETWEEN ".$AirportInfo['maxlat']." AND ".$AirportInfo['minlat']." AND Longitude BETWEEN ".$AirportInfo['maxlon']." AND ".$AirportInfo['minlon']; Gets rid of any possible issues involving trying top embed arrays within a string in PHP. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/156381-solved-search-between-two-values/#findComment-823404 Share on other sites More sharing options...
adzie Posted May 1, 2009 Author Share Posted May 1, 2009 Keith, thanks for that. Let me show some more that may help didnt think it would be needed but may help $server->wsdl->addComplexType( 'airportinfo', 'complexType', 'struct', 'all', '', array( 'maxlat' => array('name' => 'maxlat', 'type' => 'xsd:string'), 'minlat' => array('name' => 'minlat', 'type' => 'xsd:string'), 'maxlon' => array('name' => 'maxlon', 'type' => 'xsd:string'), 'minlon' => array('name' => 'minlon', 'type' => 'xsd:string') ) ); $query = "SELECT * FROM airports where Latitude BETWEEN ".$AirportInfo['maxlat']." AND ".$AirportInfo['minlat']." AND Longitude BETWEEN ".$AirportInfo['maxlon']." AND ".$AirportInfo['minlon'].""; Gives an error Quote Link to comment https://forums.phpfreaks.com/topic/156381-solved-search-between-two-values/#findComment-823449 Share on other sites More sharing options...
kickstart Posted May 1, 2009 Share Posted May 1, 2009 Hi Can you echo out $query after you have set it up? All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/156381-solved-search-between-two-values/#findComment-823453 Share on other sites More sharing options...
Ken2k7 Posted May 1, 2009 Share Posted May 1, 2009 $query = "SELECT * FROM airports where Latitude BETWEEN ".$AirportInfo['minlat']." AND ".$AirportInfo['maxlat']." AND Longitude BETWEEN ".$AirportInfo['minlon']." AND ".$AirportInfo['maxlon'].""; min before max. Quote Link to comment https://forums.phpfreaks.com/topic/156381-solved-search-between-two-values/#findComment-823461 Share on other sites More sharing options...
Linda_swe Posted May 1, 2009 Share Posted May 1, 2009 I agree Ken. Also, adzie, IMHO you might want to consider using the word thanks more often. Quote Link to comment https://forums.phpfreaks.com/topic/156381-solved-search-between-two-values/#findComment-823471 Share on other sites More sharing options...
adzie Posted May 1, 2009 Author Share Posted May 1, 2009 Linda, Appologies if I offended you? but thanks for your posts above. Quote Link to comment https://forums.phpfreaks.com/topic/156381-solved-search-between-two-values/#findComment-823492 Share on other sites More sharing options...
adzie Posted May 1, 2009 Author Share Posted May 1, 2009 Ken2k7, Thanks problem solved at the moment. Thanks to all those who contributed Quote Link to comment https://forums.phpfreaks.com/topic/156381-solved-search-between-two-values/#findComment-823495 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.