【发布时间】:2017-08-11 21:18:25
【问题描述】:
我在这里做出租车分配模块,在这里我将解释我的要求,管理员按班次将出租车分配给员工。这个细节我存储在 cab_allocation 分配表中。
cab_allocation(表名)
allocationId date cabId shiftTiming
1 2017-08-12 CBX100 1
2 2017-08-12 CBX100 2
3 2017-08-12 CBX101 3
这里 cabId CBX100 每天有两次分配,CBX101 每天有一次分配。在此之后我想跟踪这次旅行是否发生,对于这个跟踪详细信息我存储在 trip_details 表中
trip_details(表名)
tripId cabNo shiftId tripDate startTime endTime tripStatus
1 CBX100 1 2017-08-12 09:30:00 11:30:00 1
2 CBX100 2 2017-08-12 12.10.00 0
这里的cabId CBX100已经完成了他的shiftId 1,shiftId开始时间是09:30:00,结束时间是11:30:00,tripStatus 1表示本次行程完成。
下一个cabId CBX100已经开始第二班,开始时间是12.10.00,但是这次行程没有完成所以没有结束时间和行程状态
下一个cabId CBX101还没有开始他的行程,所以没有条目是这个表,
现在我的预期结果是行程不完整,我想详细了解出租车分配。这里 cab_allocation table allocationId 我正在使用 forien key trip_details table tripId。
我试过了,但我没有得到确切的结果,因为 CBX101 cabId 还没有开始他的旅行,所以trip_details 表中没有条目,所以我无法获取详细信息。
我试过这样
$sql = "SELECT * FROM `cab_allocation` a INNER JOIN trip_details b ON a.allocationId=b.tripId WHERE b.tripStatus !='1'";
$mysql = mysql_query($sql);
$count =mysql_num_rows($mysql);
if($count > 0){
while ($row = mysql_fetch_assoc($mysql)) {
$data[] = $row;
}
$arrayName = array('status' => 'success', 'count' => $count, 'data' =>$data );
echo json_encode($arrayName);
}else{
$arrayName = array('status' => 'error', 'data' =>'Data not found' );
echo json_encode($arrayName);
}
我正在获得结果
{
"status": "success",
"count": 1,
"data": [
{
"allocationId": "2",
"date": "2017-08-12",
"shiftTiming": "2",
"routeId": "1",
"cabId": "CBX100",
"tripId": "2",
"cabNo": "CBX100",
"driverId": "G2E100",
"shiftId": "2",
"tripDate": "",
"startTime": "12.10.0",
"endTime": "",
"tripStatus": "0"
}
]
}
预期结果
{
"status": "success",
"count": 2,
"data": [
{
"allocationId": "2",
"date": "2017-08-12",
"shiftTiming": "2",
"cabId": "CBX100",
},
{
"allocationId": "3",
"date": "2017-08-12",
"shiftTiming": "3",
"cabId": "CBX101",
},
]
}
【问题讨论】:
-
我们如何在没有看到任何代码或 SQL 的情况下提供帮助?
-
哦,对不起,我会上传我的代码
-
Mr@ Felippe Duarte,请查看我更新的代码,我上传了我尝试过的内容