Php 如何根据值计数增加宽度
首先,我真的很抱歉我的英语。我试图解释我的通缉令。我使用fpdf制作pdf格式的动态发票。我有一个以上的产品添加一个发票,我必须列出他们的底部。但所有发票中的产品都会计入变动。有些发票有5种产品,但有些发票有2种产品。我的问题是我使用下面的代码,但所有行都被覆盖了Php 如何根据值计数增加宽度,php,for-loop,Php,For Loop,首先,我真的很抱歉我的英语。我试图解释我的通缉令。我使用fpdf制作pdf格式的动态发票。我有一个以上的产品添加一个发票,我必须列出他们的底部。但所有发票中的产品都会计入变动。有些发票有5种产品,但有些发票有2种产品。我的问题是我使用下面的代码,但所有行都被覆盖了 $invoices_query = mysql_query("SELECT * FROM invoice_bookings WHERE invoice_code = '$invoice_code'"); while ($invoice
$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。对于其他产品,我必须制作。例如,这张发票上有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
或mysqli
PDO
- 通过转义来自外部的变量或使用准备好的语句来避免sql注入
$cnt
变量。