OfficeSales.php Source Code

1. 79 lines of code:
<?php include('_global.php'); ?>
<!DOCTYPE html>
<html lang="en-US">
<head>
    <title>Office Sales PHP</title>
</head>
<body>
    <center>
    <font face="helvetica,arial">
    <a href="javascript:window.location.href=window.location.href"><img src="logo.jpg"></a>

    <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    
        Choose an Office:
        <select name="OfficeID" onchange="javascript:this.form.submit()">
<?php
            $OfficeID = $_REQUEST['OfficeID']*1;

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

            while($record = mysql_fetch_assoc($return))
            {
                if($OfficeID == 0) $OfficeID = $record['OfficeID'];

                echo '<option ';

                if($OfficeID == $record['OfficeID']) echo 'selected="selected"';

                echo ' value="'.$record['OfficeID'].'">'.$record['OfficeLocation']."</option>\n";
            }
?>
        </select>
        <br><br>

        <table width="900" border="1" cellspacing="0" cellpadding="5">
            <tr>
                <th align="left">Agent Name</th>
                <th>SaleID</th>
                <th align="right">Amount</th>
                <th align="left">Date</th>
                <th align="left">Destination</th>
            </tr>
<?php
            $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);
            $t = 0;
            while($sale = mysql_fetch_assoc($sales))
            {
?>
                <tr>
                    <td><?php echo $sale['AgentName']; ?></td>
                    <td align="center"><?php echo $sale['SaleID']; ?></td>
                    <td align="right"><?php echo '$'.number_format($sale['Amount'],2); $t += $sale['Amount']; ?></td>
                    <td><?php echo date('M j, Y',strtotime($sale['SaleDate'])); ?></td>
                    <td><?php echo $sale['DestinationName']; ?></td>
                </tr>
<?php
            }
?>
            <tr>
                <th align="left">Total</th>
                <th></th>
                <th align="right"><?php echo '$'.number_format($t,2); ?></th>
                <th></th>
                <th></th>
            </tr>

        </table>
    </form>
    </font>
    </center>
</body>
</html>


Back