hm...
Bit confused by the months... Are there only 3 months per year?
Anyway.. I think this is easiest solved along these lines, unless you are sure that each customer will always a value for each months/cust/year code... then you can just echo each item, and place a <br> when a new customer is read.
// Sort your query, so you ge the data in a usefull order
$query = "select year,month,customer,itemcode,amount from sales_table
order by customer, itemcode, month";
$result = mysql_query($query);
$lastcustomer = ""
while($row = mysql_fetch_array($result))
{
if($row['customer'] <> $lastcustomer)
{
if($lastcustomer <> "")
{
echo $lastcustomer;
echo implode($months, '---');
}
// (re) create an empty output array
$months = array(
'year'=> '',
'T15' => array('Oct'=>'', 'Nov'=>'', 'Dec', =>''),
'K33'=> array('Oct'=>'', 'Nov'=>'', 'Dec', =>''));
}
$months[year] = $row['year'];
$months[$row['itemcode']][$row['month']] = $row['amount'];
}