如何从具有两个不同时间戳的表中提取数据 如果你知道答案?如果你知道答案,帮我吗?帮助我 <?php public function getDistanceReport($companyId,$vehicleId,$fromDate,$toDate,$

如何从具有两个不同时间戳的表中提取数据 如果你知道答案?如果你知道答案,帮我吗?帮助我 <?php public function getDistanceReport($companyId,$vehicleId,$fromDate,$toDate,$,php,zend-framework,timestamp,Php,Zend Framework,Timestamp,如何从具有两个不同时间戳的表中提取数据 如果你知道答案?如果你知道答案,帮我吗?帮助我 <?php public function getDistanceReport($companyId,$vehicleId,$fromDate,$toDate,$offset){ $fromDate, $toDate,$speed,null); $timewhere="(DATE_ADD( mt.timestamp, INTERVAL mt.gmtTimediff MINUTE ) >

如何从具有两个不同时间戳的表中提取数据
如果你知道答案?如果你知道答案,帮我吗?帮助我
<?php
public function getDistanceReport($companyId,$vehicleId,$fromDate,$toDate,$offset){
  $fromDate, $toDate,$speed,null);
    $timewhere="(DATE_ADD( mt.timestamp, INTERVAL mt.gmtTimediff MINUTE ) >='$fromDate') order by mt.timestamp asc limit 1";
    $where = "v.companyId='".$companyId."' and v.status=1 and mt.vehicleId='".$vehicleId."' and ".$timewhere;

    try{


         $sql_s="select mt.location as startLocation,DATE_ADD(mt.timestamp, INTERVAL mt.gmtTimediff MINUTE ) as startTime,v.vehicleNo,mt.distance as startDistance,v.vehicleTypeNew from fm_mt90  mt
                inner join fm_vehicle v on mt.vehicleId=v.vehicleId
                left join fm_driver d on d.driverId = v.driverId
                where ".$where;

        $startdata=$this->db->fetchRow($sql_s);


        $timewhere1="(DATE_ADD( mt.timestamp, INTERVAL mt.gmtTimediff MINUTE ) <='$toDate') order by mt.timestamp DESC limit 1";
        $where = "v.companyId='".$companyId."' and v.status=1 and mt.vehicleId='".$vehicleId."' and ".$timewhere1;

         $sql_s1="select mt.location as stopLocation,DATE_ADD(mt.timestamp, INTERVAL mt.gmtTimediff MINUTE ) as stopTime,mt.distance as stopDistance from fm_mt90  mt
                inner join fm_vehicle v on mt.vehicleId=v.vehicleId
                left join fm_driver d on d.driverId = v.driverId
                where ".$where;

        $stopdata=$this->db->fetchRow($sql_s1);

        if($stopdata['stopDistance']==null){
            $stopdata['stopDistance']=0;
        }
        if($startdata['startDistance']==null){
            $stopdata['startDistance']=0;
        }
        if($stopdata['stopDistance']>0){
            $stopdata['distanceTravelled']=$stopdata['stopDistance']-$startdata['startDistance'];
        }else{
            $stopdata['distanceTravelled']=0;
        }
        $vehicledata=array_merge($startdata,$stopdata);

        return $vehicledata;





    }catch(Exception $e){
        echo $e;
       echo $e->getMessage();
      return false;

    }    
}