php - How to get last date from all dates for each student -
i'm making query, takes driving courses students had in period , compares if student has driven courses paid for. need each student, last drives starttime, example - "martin paid 5 courses , in july had last course. did 20 other people. , administrator needs make report, in report, last course last day of fulfillment.
my php
<?php ini_set("display_errors","1"); error_reporting(e_all); include("../../config.php"); $down= array(); $xx=0; $query = "select jq.stud_id id, jq.subject name, jq.starttime endtime, (select sum(drives_count) jqcalendar stud_id=jq.stud_id , description in(5, 6, 14, 17, 18, 34)) drive_count 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 jq.starttime > '".$_get['from']."' , jq.starttime < '".$_get['till']."' , jq.description in(5, 6, 14, 17, 18, 34) , b.student_id=jq.stud_id"; $get_drives= $db->fetch_array($query); foreach($get_drives $key ) { $quant=0; $bill_id= $db->fetch_array("select cb.id bill_id, cb.payment_type, cb.bill_doc_date, bd.quant quant csn_bills cb left join csn_bills_details bd on cb.id=bd.bill_id student_id=".$key['id']." , cb.atskaite=0"); if(isset($bill_id)){ foreach ($bill_id $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); ?>
Comments
Post a Comment