我有两张桌子:
一个是旅行,另一个是物品......
这是项目表中的元组:
|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| id | item_desc | sending_from_latitude | sending_from_longitude | sending_to_latitude | sending_to_longitude | from_date | to_date |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 | Toy Gun | 15.2993265 | 74.12399599999999 | 10.8505159 | 76.2710833 | 2016-07-27 | 2016-07-30 |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
现在,这里是旅行表的元组:
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| id | trip_desc | travelling_from_latitude | travelling_from_longitude | travelling_to_latitude | travelling_to_longitude | from_date | to_date |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 | Bombay 2 Goa | 15.2993265 | 74.12399599999999 | 10.8505159 | 76.2710833 | 2016-07-27 | 2016-07-30 |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
有一个网络应用程序可以从项目获得 sending_from_latitude , sending_from_longitude , sending_to_latitude , sending_to_longitude
然后它将选择所有行程:
travelling_from_latitude
将与sending_from_latitude
匹配。travelling_from_longitude
将与sending_from_longitude
匹配。 travelling_to_latititude
将与sending_to_latitude
匹配。 travelling_to_longitude
将与sending_to_longitude
匹配。所以我写了一个函数:
function getTripListMatchingItem($Flat,$Flon,$Tlat,$Tlon,$Weight,$FromDate,$ToDate,$carrier_id,$rad)
{
$R = 6371; //Earth's Mean Radius
$queryTrip = "SELECT *, ( 6371 *
acos(
cos( radians( $Flat ) ) *
cos( radians( `travelling_from_latitude` ) ) *
cos(
radians( `travelling_from_longitude` ) - radians( $Flon )
) +
sin(radians($Flat)) *
sin(radians(`travelling_from_latitude`))
)
) `fromdistance`,
( 6371 *
acos(
cos( radians( $Tlat ) ) *
cos( radians( `travelling_to_latitude` ) ) *
cos(
radians( `travelling_to_longitude` ) - radians( $Tlon )
) +
sin(radians($Tlat)) *
sin(radians(`travelling_to_latitude`))
)
) `todistance`
FROM `trips` as Trip
WHERE from_date = '$FromDate'
AND to_date = '$ToDate'
AND wait_will_carry = '$Weight'
AND member_id = '$carrier_id'
AND isBooked = '0'
AND isActive = '1'
AND isStatus = '1'
AND isDelete = '0'";
//HAVING (`fromdistance` > $rad AND `todistance` > $rad)
//ORDER BY `fromdistance`";
echo $queryTrip;
return $this->query($queryTrip);
}
我以前称之为: -
$tripListArray = $this->Trip->getTripListMatchingItem($tripFromLat,$tripFromLong,$tripToLat,$tripToLong,$tripWeight,$tripStartDate,$tripEndDate,$carrier_id,400);
我收到了空白数据。所以我删除了
的条件//HAVING (`fromdistance` > $rad AND `todistance` > $rad)
//ORDER BY `fromdistance`";
我只检查我得到的todistance
值。
我的数据为空的原因是todistance
为空。
如果商品latitude and longitude
与行程latitude & longitude
准确一致,fromdistance
& todistance
两者都应为零。
为什么我将fromdistance
作为零而todistance
作为 NULL ?
这是我回应的实际MySQL查询:
SELECT *, (
6371 *
acos(
cos( radians( 15.2993265 ) ) *
cos( radians( `travelling_from_latitude` ) ) *
cos(
radians( `travelling_from_longitude` ) - radians( 74.12399599999999 )
) +
sin(radians(15.2993265)) *
sin(radians(`travelling_from_latitude`))
)
) `fromdistance`, (
6371 *
acos(
cos( radians( 10.8505159 ) ) *
cos( radians( `travelling_to_latitude` ) ) *
cos(
radians( `travelling_to_longitude` ) - radians( 76.2710833 )
) +
sin(radians(10.8505159)) *
sin(radians(`travelling_to_latitude`))
)
) `todistance`
FROM `trips` as Trip
WHERE from_date = '2016-07-27'
AND to_date = '2016-07-30'
AND wait_will_carry = '4'
AND member_id = '13'
AND isBooked = '0'
AND isActive = '1'
AND isStatus = '1'
AND isDelete = '0'