Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何根据值计数增加宽度_Php_For Loop - Fatal编程技术网

Php 如何根据值计数增加宽度

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

首先,我真的很抱歉我的英语。我试图解释我的通缉令。我使用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。对于其他产品,我必须制作。例如,这张发票上有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注入


真的为我工作,非常感谢你。如果我问一个问题,你能再回答我一次吗。我如何了解此列表的最后一个值?例如,如果最后一个是153,我如何学习它?在循环之外,使用
$cnt
变量。