如何在EOD tcpdf中的foreach中显示数据? [英] How do I display data in my foreach in EOD tcpdf?

查看:117
本文介绍了如何在EOD tcpdf中的foreach中显示数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是tcpdf的新手..我目前正在做一个正在使用tcpdf的项目(因为我想将表格导出为带有模板的pdf).我尝试做一些研究,发现了writeHTML()方法.通过这种方法,我现在可以制作任何html标签

I am new in the tcpdf.. I am currently doing a project where I am using the tcpdf(because I want to export my table in pdf that has a template of it). I tried to do some research and I've found the method writeHTML(). In this method I can now make any html tags

控制器

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, '');

模型

public function get($table)
    {
        $result = $this->db->get($table);
        return $result->result();
    }

问题:如何在EOD中显示我的所有数据?是否有类似writePHP()的方法?为了让我做一些php编码?

Question: How can I display all my data in EOD? Is there any method like writePHP()? To allow me to do some php coding?

推荐答案

您不能在此处document(<<<)内直接使用循环.您必须将其连接起来./p>

You can not use loop directly inside here document(<<<).You have to concatenate.Like this

  <?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;
?>

在模型中以数组格式重新运行结果.因此您可以像上面一样尝试

In your model retrun result in array format.So that you can try like above

public function get($table)
    {
        $result = $this->db->get($table);
        return $result->result_array();//it returns result in array format
    }

这篇关于如何在EOD tcpdf中的foreach中显示数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆