if ($i < count($selitems) - 1) {
        $ids .= ", ";
    }
}
//$sql="SELECT items.id,model,sn,sn3,itemtypeid,dnsname,ipv4,ipv6,label, agents.title as agtitle FROM items,agents ".
//     " WHERE agents.id=items.manufacturerid AND items.id in ($ids) order by itemtypeid, agtitle, model,sn,sn2,sn3";
$sql = "SELECT items.id,model,sn,sn3,itemtypeid,dnsname,ipv4,ipv6,label, agents.title as agtitle FROM items,agents " . " WHERE agents.id=items.manufacturerid AND items.id in ({$ids}) order by items.id";
$sth = db_execute($dbh, $sql);
$idx = 0;
$pdf = new PDF_Label(array('paper-size' => "{$labelpapersize}", 'metric' => 'mm', 'marginLeft' => $lmargin, 'marginTop' => $tmargin, 'NX' => $cols, 'NY' => $rows, 'SpaceX' => $hpitch - $lwidth, 'SpaceY' => $vpitch - $lheight, 'width' => $lwidth, 'height' => $lheight, 'font-size' => $fontsize));
$pdf->AddPage();
$pdf->SetAuthor('ITDB Asset Management');
$pdf->SetTitle('Items');
$pdf->setFontSubsetting(true);
$pdf->setPrintHeader(false);
$pdf->setPrintFooter(false);
/* skip specified labels, to avoid printing on missing label positions on reused papers*/
for ($skipno = 0; $skipno < $labelskip; $skipno++) {
    $pdf->Add_Label("", "", 0, 255, "", 0, 0, 6, 6);
}
$pages = 0;
for ($row = 1; $row <= $rows; $row++) {
    if ($pages > 30) {
        break;
    }
    for ($col = 1; $col <= $cols; $col++) {
        $r = $sth->fetch(PDO::FETCH_ASSOC);
        if (!$r) {
            break;
        }
        $idesc = $itypes[$r['itemtypeid']]['typedesc'];