创建html表php [英] Creating html table php

查看:53
本文介绍了创建html表php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我在php中还很陌生.我想创建一个html表字符串以供以后使用它mpdf,但是在构建表的过程中,代码似乎还可以,但是没有带有仅生成标题的数据的html表.

Hi guys I'm quite new in php. I want to create a string of html table to later use it mpdf but in the course of constructing my table the code seems ok but no html table with data generated just the header.

下面是我的代码:

 $html ='<div class="row">
                <div class="col-lg-12">
                 <table  width="100%" class="table table-striped table bordered">
                    <thead>
                    <tr>
                    <th class="text-left">Code</th>
                    <th class="text-left">Phone Number</th>
                    <th class="text-left">Delivery Date</th>
                    <th class="text-left">Amount HT</th>
                    <th class="text-left">Amount TVA</th>
                    <th class="text-left">Amount TTC</th>
                    <th class="text-left">Payment Mode</th>
                </tr>
                </thead >
                <tbody>';
                    foreach($estimateArray as $item):
                        if(($startDate <= date_create($item->created) && date_create($item->created) <= $endDate)){
                            $html .=  ' <tr>
                            <td class="text-left">'; echo $item->customer_name;'</td>
                            <td class="text-left">'; echo $item->document_number;'</td>
                            <td class="text-left">'; echo $item->delivery_date;'</td>
                            <td class="text-left">'; echo $item->amount_ht;'</td>
                            <td class="text-left">'; echo $item->amount_tva;'</td>
                            <td class="text-left">'; echo $item->amount_ttc;'</td>
                            <td class="text-left">'; echo $item->payment_mode;'</td>
                        </tr>';

                        } endforeach;
                        $html .= '
                                    </tbody>
                                </table>
                            </div>
                     </div>
        ';

请帮助我.

推荐答案

您正在使用echo,而不是将属性值附加到$html变量.

You are using echo instead of appending property value to $html variable.

尝试类似的东西:

<td class="text-left">' . $item->customer_name . '</td>

通过这种方式在字符串中使用变量会更加清晰:

It's much more clearer using variables in string this way:

$output = "<td class=\"text-left\">{$item->customer_name}</td>";

这篇关于创建html表php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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