我正在进行查询,其中包括学生在一段时间内所有的驾驶课程,并比较学生是否已经开出他所支付的所有课程。 我需要为每个学生,他们的最后一次驾驶开始时间,例如 - “马丁支付了5个课程,现在7月他有他的最后一个课程。其他20人也是。现在管理员需要报告,在该报告中,最后一课是实现的最后一天。
我的PHP
<?php
ini_set("display_errors","1");
error_reporting(E_ALL);
include("../../config.php");
$down= array();
$xx=0;
$query = "SELECT jq.stud_id as id,
jq.Subject as name,
jq.StartTime as endtime,
(select SUM(drives_count) FROM jqcalendar WHERE
stud_id=jq.stud_id and
Description IN(5, 6, 14, 17, 18, 34)) as drive_count
FROM jqcalendar jq
LEFT JOIN csn_bills b ON jq.stud_id=b.student_id
LEFT JOIN csn_bills_details bd ON b.id=bd.bill_id
where jq.StartTime > '".$_GET['from']."' AND
jq.StartTime < '".$_GET['till']."' AND
jq.Description IN(5, 6, 14, 17, 18, 34) AND
b.student_id=jq.stud_id";
$get_drives= $db->fetch_array($query);
foreach($get_drives as $key ) {
$quant=0;
$bill_id= $db->fetch_array("SELECT cb.id as bill_id, cb.payment_type, cb.bill_doc_date, bd.quant as quant FROM csn_bills cb
LEFT JOIN csn_bills_details bd ON cb.id=bd.bill_id WHERE student_id=".$key['id']." AND cb.atskaite=0");
if(isset($bill_id)){
foreach ($bill_id as $key2 ) {
if($key2['payment_type']==1){
$quant=$quant+$key2['quant'];
$down[$xx]['id']=$key['id'];
$down[$xx]['name']=$key['name'];
$down[$xx]['drive_count']=$key['drive_count'];
$down[$xx]['bill_id']=$key2['bill_id'];
$down[$xx]['bill_date']=$key2['bill_doc_date'];
$down[$xx]['endtime']=$key['endtime'];
$down[$xx]['payment_type']=$key2['payment_type'];
$down[$xx]['quant']=$quant;
}
}
}
else{
echo "No report";
}
$xx++;
}
//echo json_encode($get_drives);
echo json_encode($down);
//echo json_encode($bill_id);
?>