Jump to content

[SOLVED] search between two values


adzie

Recommended Posts

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'

Link to comment
https://forums.phpfreaks.com/topic/156381-solved-search-between-two-values/
Share on other sites

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

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'];
}

?> 

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

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

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.