<style>
table {
    border-collapse: collapse;}
th {
    background-color: #808080;
    color: white;}
th, td {
    text-align: left;
    padding: 2px;
    #width:1250px;
    font:normal 11px/2.0em Sans-Serif;}

tr:nth-child(even){background-color:#eee}
tr:hover {background-color: #f5f5f5}
pragra{color:#959595;font:normal 12px/2.0em Sans-Serif;}
</style>


<?php
$con=mysqli_connect("localhost","primarysales","S5L7lF01EQZvQrGK","primarysales_diana");
$result=mysqli_query($con,"select naration as dealer,dates,agent_names,regions,territory_names, sum(box_qty*box_price)+sum(pcs_qty*pcs_price) as grand_val,sum(box_qty*box_price)*discount_rates as volum from rc_invoices where dates between '2018-01-01' and '2018-01-31' and  regions<>'MODERN TRADE-1' and regions<>'MODERN TRADE-2' and naration<>'' group by naration,agent_names order by regions" );
print"<br>";

echo "<table >
<tr>
<th>Date</th>
<th>Direct Dealer</th>
<th>Agent Name</th>
<th>Region</th>
<th>Territory</th>
<th>Primary Value</th>
<th>Discount</th>
</tr>";

while($row = mysqli_fetch_array($result)) {
echo "<td>" . $row['dates'] . "</td>";
echo "<td>" . $row['dealer'] . "</td>";
echo "<td>" . $row['agent_names'] . "</td>";
echo "<td>" . $row['regions'] . "</td>";
echo "<td>"  . $row['territory_names'] . "</td>";
echo "<td>" . number_format($row['grand_val'],2, '.', ',') . "</td>";
echo "<td>" . number_format($row['volum'],2, '.', ',') . "</td>";
echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>

