Hi Barand, i try to follow your code but i did not get it. and difficult to convert using MS Access DB or using ODBC.
take a look my code and it work but wrong column base on header.
Hope someone can take a time to analyze code below
$sql1 = "SELECT DISTINCT BRANCH FROM sales ORDER BY BRANCH asc";
$rs = odbc_exec($connect, $sql1);
if(!$rs) {exit("Error in SQL");}
echo"<table class='table table-bordered'>";
$result_branch = array();
while (odbc_fetch_row($rs))
{
$result_branch[] = odbc_result($rs,'branch');
}
echo "<tr style = 'background-color:#ccc;'>";
echo "<td style = 'font-weight:bold;font-size:12px;'>";
echo "BRANCH / DATE";
echo "</td>";
$sqldate = "SELECT DISTINCT Date FROM sales where Date BETWEEN #8/1/2015# AND #8/30/2015# ORDER BY Date asc";
$rs1 = odbc_exec($connect, $sqldate);
$result_date = array();
while (odbc_fetch_row($rs1))
{
$result_date[] = odbc_result($rs1,'Date');
}
foreach($result_date as $rs_date)
{
echo "<td style = 'font-weight:bold;font-size:12px;'>";
echo substr("$rs_date",0, 10);
echo "</td>";
}
echo "<td style = 'font-weight:bold;'>" . TOTAL . "</td>";
echo "</tr>";
foreach($result_branch as $rs_branch)
{
echo "<tr>";
echo "<td style = 'font-weight:bold; width:70px;background-color:#ccc;font-size:12px;'>". $rs_branch . "</td>";
$sql2 = ("SELECT Date,SumOftotal_inc,BRANCH FROM sales WHERE BRANCH = '$rs_branch' ORDER BY Date asc");
$rs2 = odbc_exec($connect, $sql2);
$result_total = array();
$result_date2 = array();
while (odbc_fetch_row($rs2))
{
$result_total[] = odbc_result($rs2,'SumOftotal_inc');
$result_date2[] = odbc_result($rs2,'Date');
}
foreach($result_total as $rs_total)
{
echo "<td style = 'color:#fe0000;font-size:12px;'>₱". number_format($rs_total, 2). "<input type = 'hidden' name = 'hdden' value = '$result_date2'></td>";
}
echo "<td style = 'color:#000;font-weight:bold;'> ₱";
$mval = array_sum($result_total);
echo number_format($mval, 2);
echo "<input type = 'hidden' name = 'hdden' value = '$result_date2'></td>";
echo "</tr>";
}
echo "<tr>";
echo "<td style = 'font-weight:bold;'>";
echo "Total";
echo "</td>";
echo "</tr>";
echo "</table>";