如何根据值计数增加宽度

how to increase width according to value count

首先我真的很抱歉我的英语不好。我试着解释我想要的。我使用 fpdf 以 pdf 格式制作动态发票。我有不止一种产品可以添加一张发票,我必须将它们列在底部。但是产品计数在所有发票中都有变化。有些发票有 5 种产品,有些发票有 2 种产品。我的问题是我使用下面的代码但所有行都被覆盖了。

$invoices_query = mysql_query("SELECT * FROM invoice_bookings WHERE invoice_code = '$invoice_code'");
while ($invoices = mysql_fetch_array($invoices_query)) {

$customers_name = $invoices['customer_name'];

$pdf->Ln(0);
$pdf->Cell(21,123,$invoice_number,0,0,'L',0);   // empty cell with left,top, and right borders
$pdf->Cell(30,123,$customers_name,0,0,'L',0);
$pdf->Cell(20,123,$date,0,0,'L',0);
$pdf->Cell(20,123,$time,0,0,'L',0);
$pdf->Cell(30,123,$suburb_from,0,0,'L',0);
$pdf->Cell(34,123,$suburb_to,0,0,'L',0);
$pdf->Cell(10,123,'% ' . $tax_percent,0,0,'L',0);
$pdf->Cell(25,123,'$ ' . $invoice_price,0,0,'R',0);

}

您可以看到保证金的价值。如您所见,它是 123。例如,我必须将此值增加到 132。对于我必须制作的其他产品 142。例如,这张发票中有 5 种产品,我必须这样制作;

前123 第二个133 第三个 143 第四个 153 第五个163

但我真的不知道该怎么做。

像这样。添加一个计数器,对其进行初始化,并始终增加 10。

$cnt = 123; //Init the counter
while ($invoices = mysql_fetch_array($invoices_query)) {

    $customers_name = $invoices['customer_name'];

    $pdf->Ln(0);
    $pdf->Cell(21, $cnt, $invoice_number, 0, 0, 'L', 0);   // empty cell with left,top, and right borders
    $pdf->Cell(30, $cnt, $customers_name, 0, 0, 'L', 0);
    $pdf->Cell(20, $cnt, $date, 0, 0, 'L', 0);
    $pdf->Cell(20, $cnt, $time, 0, 0, 'L', 0);
    $pdf->Cell(30, $cnt, $suburb_from, 0, 0, 'L', 0);
    $pdf->Cell(34, $cnt, $suburb_to, 0, 0, 'L', 0);
    $pdf->Cell(10, $cnt, '% ' . $tax_percent, 0, 0, 'L', 0);
    $pdf->Cell(25, $cnt, '$ ' . $invoice_price, 0, 0, 'R', 0);
    $cnt = $cnt  + 10; //Incrase it in the loop.
}

注意

  • 不要使用 mysql 函数,它们已被弃用。请改用 mysqliPDO

  • 通过转义来自外部的变量或使用准备好的语句来避免 sql 注入。