Php 如何在EOD tcpdf中显示foreach中的数据?
我是tcpdf的新手。。我目前正在做一个使用tcpdf的项目(因为我想导出带有模板的pdf格式的表)。我试着做了一些研究,发现了writeHTML()方法。在这个方法中,我现在可以创建任何html标记 控制器Php 如何在EOD tcpdf中显示foreach中的数据?,php,codeigniter,tcpdf,Php,Codeigniter,Tcpdf,我是tcpdf的新手。。我目前正在做一个使用tcpdf的项目(因为我想导出带有模板的pdf格式的表)。我试着做了一些研究,发现了writeHTML()方法。在这个方法中,我现在可以创建任何html标记 控制器 public function testing(){ $this->load->library('Pdf'); $this->load->model('newModel'); $data['accounts'] = $
public function testing(){
$this->load->library('Pdf');
$this->load->model('newModel');
$data['accounts'] = $this->newModel->get('users');
$this->load->view('admin/testing',$data);
}
查看
$txt = <<<EOD
<table cellspacing="0" cellpadding="1" border="1">
<tr>
<td>COL 2 - ROW 1</td>
<td>COL 3 - ROW 1</td>
</tr>
<tr>
<?php foreach($accounts as $try):?>
<td>$try->first_name</td>
<td>Hala2 </td>
<?php endforeach?>
</tr>
</table>
EOD;
$pdf->writeHTML($txt, true, false, false, false, '');
问题:如何在EOD中显示所有数据?有没有像writeph()这样的方法?允许我做一些php编码吗?您不能在
这里的文档中直接使用循环(如果您希望从数据库获取数据并将其转换为html和创建pdf,请使用mpdf替代tcpdf)
您的模型代码是什么?您想在哪里显示数据?在我的模型中,它只是$this->db->get($table);在其中获取formar结果。再次检查我的论坛,我已经把我的模型放在了EOD
的表格中。我说的对吗?我也试过了,但仍然不起作用,先生。我没有显示任何编辑过的答案。但我认为你不能在这里循环文档。那么,我应该把我的循环放在哪里?你可以连接。@天使像上面一样尝试,希望它会大有成效。
public function get($table)
{
$result = $this->db->get($table);
return $result->result();
}
<?php
$accounts = array('name'=>'angle');//assumed array
//print_r($accounts);
$txt = <<<EOD
<table cellspacing="0" cellpadding="1" border="1">
<tr>
<td>COL 2 - ROW 1</td>
<td>COL 3 - ROW 1</td>
</tr>
EOD;
foreach($accounts as $key=>$value){
$txt.=<<<EOD
<tr>
<td>{$accounts['name']}</td>
<td>It is easy</td>
</tr>
EOD;
}
$txt.=<<<EOD
</table>
EOD;
echo $txt;
?>
public function get($table)
{
$result = $this->db->get($table);
return $result->result_array();//it returns result in array format
}