$date = mysqli_fetch_array($dateR, MYSQLI_NUM); $where = "timestamp > '{$date['0']}'"; $query = "SELECT ID, DATE_FORMAT(billdate, '%M %D'), amount, description, firstname\n FROM bills INNER JOIN payers\n ON (bills.payerid = payers.payerid)\n WHERE {$where}"; $header = " {$date['1']} to " . date('F jS'); } $payersQ = "SELECT firstname FROM payers WHERE active=1"; $payersR = mysqli_query($dbc, $payersQ); while ($row = mysqli_fetch_array($payersR)) { $payer[$row[0]] = 0.0; } $billQ = "SELECT ifnull(sum(amount),0) AS total, firstname\n FROM bills INNER JOIN payers\n ON (bills.payerid = payers.payerid)\n WHERE {$where}\n GROUP BY firstname\n ORDER BY firstname ASC"; $billR = mysqli_query($dbc, $billQ); $pdf = new fpdf('P', 'mm', 'Letter'); $pdf->setFont('Times', 'B', 20); $pdf->addPage(); $pdf->setY(20); $pdf->cell(0, 12, 'Bills from ' . $header, 0, 1, 'C'); $pdf->setY(40); $total = 0.0; while ($row = mysqli_fetch_array($billR, MYSQLI_NUM)) { $payer[$row[1]] = $row[0]; $total += $row[0]; } $num = mysqli_num_rows($payersR); $avg = $total / $num; $pdf->setFont('Times', 'B', 16); // 216 mm total, 203 writable $pdf->setX(7.5); $pdf->cell(75, 10, 'Name', 1, 0, 'C'); $pdf->cell(42, 10, 'Amount Paid', 1, 0, 'C'); $pdf->cell(42, 10, '', 1, 0, 'C');