<?php
include("../../db.php");

$schoolCode = $_GET['school_code'];

$message = "Unknown Error";
$status = 0;

$array = array();

if($schoolCode != ''){
    $result = $db->getRows("select * from gps_user where school_code='$schoolCode'");
    
    
    if($result){
    
    foreach($result as $rows){
        $driver_id = $rows["id"];
        
        $time_driver = $db->getVal("select timestamp from gps_tracking where driver_id=$driver_id");
        if(!$time_driver){ $time_driver = "NA"; }
        
        $rows["last_loc_time"] = $time_driver;
        array_push($array,$rows);
    }   
       
       
        $status   =  1;
        $message  =  "Success";
        
    }else{
        $message = "No bus found for your school!";
    }
}else{
    $message = "School code required!";
}

echo json_encode(array("status"=>$status,"data"=>$array,"message"=>$message));