PHP文件中生成HTML报表

PHP文件中生成HTML报表

主要步骤

目的,php文件发送邮件,邮件内容包含报表。写在一个文件中,让html页面里的一个标签的value值设置成php传递的数据;优化方法,数据写到一个文件里,用js去取数据,使用三个文件index.php,index.html,

  1. 写好HTML报表样式
  2. php文件,前端页面结果,生成报表------如何读取结果-----从数据库读取信息
  3. 报表样式html格式,直接在邮件里面生成-------单独写,传入结果;

邮件样式,写到PHP文件

邮件报表样式设置

 public function writeEmailHead($title){
        $html = "";
        $html = $html."<!DOCTYPE html><html lang=\"zh\"><head><meta charset=\"UTF-8\"><title>".$title."</title><style type=\"text/css\">".
            "body {color:#333;font:14px Arial, Helvetica, sans-serif, Simsun;}".
            ".title {font-weight:bold} p{font-size:17px}".
            ".subtitle {margin-top: 3px; margin-bottom: 3px;}".
            "table {width:50%;border-collapse:collapse;border-spacing:0;white-space:nowrap}".
            ".table-status th {height:32px;width:105px;line-height:20px;padding:0 10px;font-size:14px;font-weight:600;text-align:left;border:1px solid #000;white-space:nowrap;}".
            ".foot{margin-top: 100px;font-size: 13px;}".
            "</style></head>".
            "<body>";

        return $html;
    }

PHP语句与html同时存在
html与PHP语句之间,通过以下格式连接
$html .=<<<EOF... EOF;

    public function writeEmailCaseContent($caseNum,$params){
        $html = '';
        $html .= <<<EOF
<div>
    <h3>详情</h3>
    <article class="first-level-article">
    <table class="table-status" >
        <thead style="background-color: #fff;">
        <tr>
            <td class="first-th ng-binding" >序号</td>
            <td class="first-th ng-binding">ID</td>
        </tr>
        </thead>
        <tbody >
EOF;
        for($i = 0; $i < $caseNum; $i++){
            $testID = $params[$i]['testID'];    
            $html .= "<tr><td>$i</td>";
            $html .= "<td>$testID</td>";
        }
        $html .= "</tbody></table></article></div>";
        return $html;
    }

html 根据报表内容调节样式

style=white-space:nowrap;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值