OfficeSales_api.php Source Code

1. 36 lines of code:
<?php
    include('_global.php');

    $OfficeID = $_REQUEST['OfficeID']*1;

    $function = $_REQUEST['function'];

    $records = [];

    if ( $function == 'offices' ) {

        $return = mysql_query("SELECT * FROM OFFICE ORDER BY OfficeLocation", $conn);
        $message = mysql_error($conn);

        while($record = mysql_fetch_assoc($return)) array_push($records, $record);
    }
    else if ( $function == 'sales' ) {

       $sql = "SELECT * 
           FROM SALE LEFT JOIN AGENT ON AgentKey=AgentID LEFT JOIN DESTINATION ON DestinationID=DestinationKey
           WHERE OfficeKey='$OfficeID'
           ORDER BY AgentName, SaleDate";

       $sales = mysql_query($sql, $conn);
       $message = mysql_error($conn);

       while($sale = mysql_fetch_assoc($sales)) array_push($records, $sale);

    }

    header('Content-Type: application/json');

    echo json_encode([ "function" => $function, "message" => $message, "OfficeID" => $OfficeID, "records" => $records ], JSON_PRETTY_PRINT);
?>


Back