我有一个带有旅程的数据库,我试图在表中找到通过两个查询的所有结果(比如INTERSECT),但我只能得到它给我两组结果。查询搜索两端半径范围内的所有记录sql是旅程的开始,sql2是旅程的结束
<?php
include_once 'dbconnect.php';
// Get lat and long by address
$dlocation = 'SW1A 0AA';
$address = $dlocation; // Google HQ
$prepAddr = str_replace(' ','+',$address);
$geocode=file_get_contents('https://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
$output= json_decode($geocode);
$lat = $output->results[0]->geometry->location->lat;
$lng = $output->results[0]->geometry->location->lng;
// Get lat and long by address
$dlocation = 'bb97bp';
$address = $dlocation; // Google HQ
$prepAddr = str_replace(' ','+',$address);
$geocode=file_get_contents('https://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
$output= json_decode($geocode);
$lat2 = $output->results[0]->geometry->location->lat;
$lng2 = $output->results[0]->geometry->location->lng;
$sql = "SELECT adpastrip_id, ( 3959 * acos( cos( radians($lat) ) * cos( radians( lat1 ) ) * cos( radians( long1 ) - radians($lng) ) + sin( radians($lat) ) * sin( radians( lat1 ) ) ) ) AS distance FROM addgoodstrip HAVING distance < 10 ORDER BY distance LIMIT 0 , 20";
$result = $con->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$id = $row['adpastrip_id'];
}
}
$sql2 = "SELECT adpastrip_id, ( 3959 * acos( cos( radians($lat2) ) * cos( radians( lat2 ) ) * cos( radians( long2 ) - radians($lng2) ) + sin( radians($lat2) ) * sin( radians( lat2 ) ) ) ) AS distance FROM addgoodstrip HAVING distance < 10 ORDER BY distance LIMIT 0 , 20 ";
$result2 = $con->query($sql2);
if ($result2->num_rows > 0) {
// output data of each row
while($row2 = $result2->fetch_assoc()) {
$id2 = $row2['adpastrip_id'];
}
}
?>