This is my code:
<?php
$conn=odbc_connect("julcom2","","");
if($conn)
{
echo "<table border=1>";
//---DISPLAY SALESMAN
$sqlloc="select locid,location from tbllocation where status=0 order by arrangement";
$rowloc =odbc_exec($conn,$sqlloc);
while(odbc_fetch_row($rowloc))
{
$locids = odbc_result($rowloc,1);
$locnames = odbc_result($rowloc,2);
echo "<tr bgcolor='orange'><th colspan=5 align=left>" . $locnames . "</th></tr>";
echo "<tr><th>Item</th><th>Sellin</th><th>Withdrawal</th><th>Return</th><th>Sell-out</th></tr>";
//----DISPLAY ITEM
$sqlitem="SELECT itemid,itemname FROM tblitem where status=0 ORDER BY itemassign";
$rowitem = odbc_exec($conn,$sqlitem);
while(odbc_fetch_row($rowitem))
{
$itemcodes=odbc_result($rowitem,1);
$items= odbc_result($rowitem,2);
echo "<tr><td>" . $items;
//------DISPLAY DSR
$sqldsr = "select sum(sellin),sum(transfer),sum(rs),sum(sales) FROM may_dsr ";
$sqldsr .= "where location='" . $locids . "' and itemcode=" . $itemcodes;
$sqldsr .= " group by location,itemcode";
$rowdsr=odbc_exec($conn,$sqldsr);
while(odbc_fetch_row($rowdsr))
{
$rr = number_format(odbc_result($rowdsr,1));
$dr= number_format(odbc_result($rowdsr,2));
$return= number_format(odbc_result($rowdsr,3));
$sellout= number_format(odbc_result($rowdsr,4));
echo "<td> " . $rr . "<td> " . $dr . "<td> " . $return . "<td> " . $sellout . "</tr>";
} //END OF DISPLAY DSR
}//END OF DISPLAY ITEM
}//end of DISPLAY LOCATION
//echo "</tr>";
echo "</table>";
}//end of if ($conn)
?>
supposing the code's output is like this:
Salesman1
Item Sellin Withdrawal Return Sell-out
G100 200 100 50 0
G300 300 50 25 0
G500 150 20 0 0
Salesman2
Item Sellin Withdrawal Return Sell-out
G100 250 50 6 0
G300 350 70 50 0
G500 250 50 12 0
how to make the output like this
Salesman1 Salesman2
Item Sellin Withdrawal Return Sell-out Sellin Withdrawal Return Sell-out
G100 200 100 50 0 250 50 6 0
G300 300 50 25 0 350 70 50 0
G500 150 20 0 0 250 50 12 0