<?php 
$ids = explode(',',$_REQUEST['ids']);
$db = $GLOBALS['db'];

$res = $db->query("SELECT code, name, SUM(quantity) AS qty FROM ecmsaleitems WHERE ecmsale_id IN ('".implode("','", $ids)."') GROUP BY ecmproduct_id ORDER BY code");
$t = '<table style="border: 1px solid black; border-collapse: collapse;"><tr><td><b>Kod</b></td><td><b>Nazwa</b></td><td><b>Ilość</b></td></tr>';

while ($r = $db->fetchByAssoc($res))
	$t.='<tr><td style="border: 1px solid black;">'.$r['code'].'</td><td style="border: 1px solid black;">'.$r['name'].'</td><td style="border: 1px solid black;">'.$r['qty'].'</td></tr>';

$t.='</table>';

echo $t;
?>