gpt4 book ai didi

php - 尝试在 pdf 上打印 2 列中的 2 个数组,但第一个数组打印正确,而第二个数组打印聚集的值,值彼此重叠

转载 作者:行者123 更新时间:2023-11-29 21:14:12 25 4
gpt4 key购买 nike

$sql = " SELECT Salary,Bonus,Housing_Allowance,Transport_Allowance,Travel_Allowance,Vehicle_Allowance,Cellphone_Allowance,Entertainment_Allowance,Company_Car,Medical_Allowance FROM $tb2_name WHERE Month='$month' AND Year='$year' AND Employee_Number='$user'";

$result = mysqli_query($conn, $sql);
$rows = mysqli_fetch_assoc($result);

// This code works fine as the array are printed under each other . thanks to the \n

$data = array();
foreach($rows as $key => $value) {
if($value > 0) {
$me = $key . " : " . $value . "\n";
$pdf->MultiCell(63, 10, $me, 2);
}
}

上面的代码工作得很好,因为数组值在 pdf 页面上打印在彼此下面,而不是聚集。当我尝试在旁边的列中执行相同的操作时,问题出现在下一段代码

$pdf->SetXY($x + 35, $y);

$col2="Deductions Other Deductions ";


$col3="Deductions\n \n $DSocial_Security \n $DContributions \n $DVehicle_Allowance \n $Other_Deductions";

$wql = " SELECT Housing_Allowance,Vehicle_Allowance,Company_Car,DContributions,Pension, Provident_Fund,Retirement_Annuity,Study_Policy FROM $tb2_name WHERE Month='$month' AND Year='$year' AND Employee_Number='$user'";

$results = mysqli_query($conn, $wql);
$rows1 = mysqli_fetch_assoc($results);

问题就来了。执行此操作时,结果会打印在彼此之上并聚集在一起,而不是像\n 所说的那样彼此在下面。

$data1 = array();
foreach($rows1 as $key => $value) {
if($value > 0) {
$me = $key . " : " . $value . "\n";
$pdf->SetXY($x + 60 ,$y);
$pdf->MultiCell(63, 10, $me, 3);
}


}

the above code does not print the array so that the values line up under each other but the values line up on top of each other and are clustered.


$pdf->SetXY($x + 95 ,$y);

$pdf->SetXY($x + 120 ,$y);
$pdf->MultiCell(63, 10, $col2, 3);

最佳答案

根据我的说法,按照您的代码/声明,请增加您的 $x 定位,如下所示:

$data1 = array();
foreach($rows1 as $key => $value) {
if($value > 0) {
$me = $key . " : " . $value . "\n";
$pdf->SetXY($x ,$y);
$pdf->MultiCell(63, 10, $me, 3);
$x= $x + 5; // insert this line
}
}

首先,MultiCell 代码默认会增加 x,因此它可以完美工作。在第二个代码中,您指定了 SetXY() 进行定位,因此每次您都必须根据所需的边距增加 X 位置......感谢

关于php - 尝试在 pdf 上打印 2 列中的 2 个数组,但第一个数组打印正确,而第二个数组打印聚集的值,值彼此重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36101871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com