du7999 2015-01-21 16:05 采纳率: 100%
浏览 43
已采纳

如何根据值计数增加宽度

First of all i am really sorry for my english. I try to explain my wanted. I use fpdf to make dynamic invoice in pdf. I have more than one product to add one invoice and i must list them sub-bottom. But products counts change in all invoices. Some invoice has 5 products but some invoice has 2 products. My problem is i use code below but all lines overrided.

$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);

}

You can see value of margin. It's 123 as you can see. I must increase this value to 132 for example. And for other product 142 i must make. For example there are 5 products in this invoice i must make like this ;

first 123 second 133 third 143 fourth 153 fifth 163

but i really don't know how can i do this.

  • 写回答

1条回答 默认 最新

  • donglan9651 2015-01-21 16:10
    关注

    As this. Add a counter, initialize it, and always incrase with 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.
    }
    

    NOTE

    • Do not use mysql functions, they are deprecated. Use mysqli or PDO instead.

    • Avoid sql injections by escaping your variables comes from outside, or use prepared statements.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。