Creating html table php

醉酒当歌 提交于 2019-12-02 10:06:21

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

Try something like:

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

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

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

Append the values to your $html instead of echoing.

foreach($estimateArray as $item):
if(($startDate <= date_create($item->created) && date_create($item->created) <= $endDate)){
    $html .=  ' <tr>
    <td class="text-left">'. $item->customer_name . '</td>
    <td class="text-left">'. $item->document_number . '</td>
    <td class="text-left">'. $item->delivery_date.'</td>
    <td class="text-left">'. $item->amount_ht.'</td>
    <td class="text-left">'. $item->amount_tva.'</td>
    <td class="text-left">'. $item->amount_ttc.'</td>
    <td class="text-left">'. $item->payment_mode.'</td>
</tr>';

} endforeach;

Just to clarify this, try dropping in this code.

             foreach($estimateArray as $item):
                    if(($startDate <= date_create($item->created) && date_create($item->created) <= $endDate)){
                        $html .=  ' <tr>
                        <td class="text-left">'.$item->customer_name.'</td>
                        <td class="text-left">'.$item->document_number.'</td>
                        <td class="text-left">'.$item->delivery_date.'</td>
                        <td class="text-left">'.$item->amount_ht.'</td>
                        <td class="text-left">'.$item->amount_tva.'</td>
                        <td class="text-left">'.$item->amount_ttc.'</td>
                        <td class="text-left">'.$item->payment_mode.'</td>
                    </tr>';

                    } endforeach;

There are three methods I can recommend.

1. method

Close PHP code and add PHP code in HTML.

<?php
// there is PHP codes
?>
<table>
  <tr>
    <td><?php echo $value; ?></td>
  </tr>
</table>
<?php
// continue with PHP
?>

2. method

Print HTML code with PHP.

Remember! To work with PHP values, print with double quotes ("). Use escape character (\) if you need to use double quotes. (Ex: class=\"demoTable\")

<?php
echo "
  <table class='demoTable'>
    <tr>
      <td>$value</td>
    </tr>
  </table>
";
?>

3. method

Use PHP heredoc or nowdoc.

Now you can use double and single quotes in your code.

<?php
$html = <<<HTML
  <table class="demoTable" style="font-family: 'Open Sans';">
    <tr>
      <td>$value</td>
    </tr>
  </table>
HTML;
echo $html;
?>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!