<?php	
require_once('connectionSC.php');
if(isset($_GET['spv'])){
$sql = "SELECT nasabah,plafond,marketing,surveyor,tanggal_add,status FROM hasil WHERE spv LIKE '%".$_GET['spv']."%' ORDER BY tanggal_add DESC";

if(!$conn->query($sql)){
    echo "Error in connecting to Database.";
}
else{
    $result = $conn->query($sql);
    if($result->num_rows > 0){
        $return_arr['hasil'] = array();
        
        while($row = $result->fetch_array()){
            // Check if surveyor is not 'EXPRESS', set to 'Reguler' otherwise keep the original value
            $surveyor = ($row['surveyor'] != 'EXPRESS') ? 'REGULER' : $row['surveyor'];
            
            // Add the result into the response array
            array_push($return_arr['hasil'], array(
                'surveyor' => $surveyor, // Set to 'Reguler' if not 'EXPRESS'
                'nasabah' => $row['nasabah'],
                'plafond' => $row['plafond'],
                'status' => $row['status'],
                'tanggal_add' => $row['tanggal_add'],
                'marketing' => $row['marketing'],
            ));
        }
        
        // Return the JSON response
        echo json_encode($return_arr);
    }
}
}
?>
