query($sql); $count=0; if ($result->num_rows > 0) { // Array to hold the results $rows = array(); // Fetch data from each row and add it to the array while($row = $result->fetch_assoc()) { $rows[] = $row; $count = $count + 1; } if($count > 0){ $stat =''; $requestUPdate = 'Visible'; }else{ $stat ='- NO Service Update - '; $requestUPdate = ''; } $getSA = "SELECT t1.assigned_service_advisor,t1.date,t1.time,t2.id AS saID,t2.employee_id,t2.first_name,t2.last_name,t2.name AS SANAME,t3.id,t3.name AS dealName FROM autoph_ahg_crm.service_bookings t1 LEFT JOIN autoph_ahg_hr.users t2 ON t1.assigned_service_advisor = t2.employee_id LEFT JOIN autoph_ahg_hr.dealerships t3 ON t1.dealer_id = t3.id WHERE t1.id='$serviceID' GROUP BY t2.employee_id"; $qSA = mysqli_query($conn,$getSA); $cntqSA = mysqli_num_rows($qSA); if($cntqSA > 0){ while($sa = mysqli_fetch_array($qSA)){ $saID = $sa['saID']; $saName = $sa['SANAME']; $bookDate = $sa['date']; $bookTime =date('h:i A', strtotime($sa['time'])); //$bookTime = $sa['time']; $dealName = $sa['dealName']; } }else{ $saID = ''; } // Output the result in JSON format header('Content-Type: application/json'); echo json_encode([$rows,"Count" => "$count","status" => "$stat","RequestUpdate" =>"$requestUPdate","saID" =>"$saID","saName" =>"$saName","bookDate" =>"$bookDate","bookTime" =>"$bookTime","dealName"=>"$dealName"]); } else { $sqX ="SELECT t1.assigned_service_advisor,t1.date,t1.time,t2.id AS saID,t2.employee_id,t2.first_name,t2.last_name,t2.name SANAME,t3.id,t3.name AS dealName FROM autoph_ahg_crm.service_bookings t1 LEFT JOIN autoph_ahg_hr.users t2 ON t1.assigned_service_advisor = t2.employee_id LEFT JOIN autoph_ahg_crm.dealerships t3 ON t1.dealer_id = t3.id WHERE t1.id='$serviceID' GROUP BY t2.employee_id"; $sqQ = mysqli_query($conn,$sqX); while($sq = mysqli_fetch_array($sqQ)){ $saName = $sq['SANAME']; $bookDate = $sq['date']; //$timestamp = strtotime($timeString); //date('h:i:s A', $timestamp); $bookTime =date('h:i A', strtotime($sq['time'])); $dealName = $sq['dealName']; } $requestUPdate = ''; $stat ='- NO Service Update - '; echo json_encode([$rows,"Count" => "$count","status" => "$stat","RequestUpdate" =>"$requestUPdate","saID" =>"$saID","saName" =>"$saName","bookDate" =>"$bookDate","bookTime" =>"$bookTime","dealName"=>"$dealName"]); } } // Close connection $conn->close(); ?>