php 如何以pdf格式单独打印每个数组的值?

bqf10yzr  于 2023-10-15  发布在  PHP
关注(0)|答案(2)|浏览(93)

我想打印每个数组的值在PDF格式,因为这个程序持有大量的数组,永远不会在数据方面的具体。
这是我的代码:模型中的$this->submissionPSDirectCost函数,调用数据库中的所有数据。

$ps_data_string = "";
        foreach ($this->submissionPSDirectCost as $ps) {
            $ps_data = [
                "<b>" . (($ps->ps_type == 0) ? "Salary" : "Honoraria") . "</b>",
                "<br>",
                $ps->ps_quantity ,
                $ps->title,
                "at",
                $ps->salary ,
                "/Month x",
                $ps->ps_num_duration,
                $ps->mode_payment,
                "<br>",
            ];
            $ps_data_string .= "<tr><td colspan=\"1\">" . implode(" ", $ps_data) . "</td></tr>";
            
        }

        $ps_amount = " ";
        foreach ($this->submissionPSDirectCost as $ps) {
            $psamount =[
            $ps->amount,
            "<br>",
            ];
            $ps_amount .= "<td colspan=\"1\">" . implode(" ", $psamount) . "</td>";
        }

然后这是我的html内联代码调用$ps_data_string

'.$ps_data_string.''.$ps_amount.'

CLICK THIS PICTURE: the amount should be in the column of Total approved budget

gpfsuwkq

gpfsuwkq1#

正如另一个答案中所建议的,直接在循环内创建行应该可以达到目的。但是,如果我正确理解了这个要求,您需要(在其中移动$ps_data$ps_data_string)仅在连接$ps_data的所有13个元素之后创建行

foreach ($this->submissionPSDirectCost as $ps) {
  $ps_data = null;
  $ps_data[] = ($ps->ps_type == 0) ? "Salary" : "Honoraria";
  //remaining 12 elements of $ps_data to follow
  $ps_row = implode(" ", $ps_data);
  $ps_data_string .= "<tr><td colspan=\"3\">$ps_row</td></tr>";
}

然后在html中使用<table><?php echo $ps_data_string;?></table>

h7wcgrx3

h7wcgrx32#

可以按如下方式修改代码:

($this->submissionPSCost as $ps) {
$ps_data_row = array $ps_data_row = ($ps->ps_type == ) ? "Salary" : "Haria";
$ps_data_row[] = $ps->ps_quantity;
$ps_data_row[] = $ps->title;
$ps_data_row[] = "at";
$ps_data_row[] = $ps->salary;
$ps_data_row[] = "/Month x";
$ps_data_row[] = $ps->ps_num_duration;
$ps_data_row[] = $ps->mode_payment;
$ps_data_row[] = " ";
$ps_data_row[] = " ";
$ps_data_row[] = $ps->amount;
$ps_data[] = '<tr><td>'.implode('</td><td>', $ps_data_row).'</td></tr>';
}

$ps_data_string = implode("", $ps_data);

现在,每行数据都存储在$ps_data_row数组中,然后用</td><td>将其内爆以创建HTML表格行结构。然后将生成的行添加到$ps_data数组。
最后,您可以在HTML模板中使用此$ps_data_string,如下所示:

>
php echo $ps_data_string; ?>
</table>

相关问题