【问题标题】:PHP TCPDF heredocPHP TCPDF heredoc
【发布时间】:2015-12-29 08:19:03
【问题描述】:

我在我的 TCPDF 中的 heredoc 中得到了这个。 我基本上想用我的数据库数据创建一个动态pdf。

        $html = <<<EOD
        <table border="1">
            <thead>
                <tr>
                    <th>firstname</th>
                    <th>lastname<th>
                </tr>
            </thead>
            <tbody>
                <tr>
                   <th></th>
                   <th></th>
                </tr>
            </tbody>
        </table>
EOD;

我想像这样动态地从我的数据库中创建数据。

    <?php
    foreach($result_set as $result) {
    ?>
    <tr>
        <td>
            <?php echo $result['firstname']; ?>
        </td>
        <td>
            <?php echo $result['lastname']; ?>
        </td>
    </tr>
    <?php
    }
    ?>

到目前为止我已经尝试过了,但我找不到合适的解决方案:

        $html = <<<EOD
        <table border="1">
            <thead>
                <tr>
                    <th>Vorname</th>
                    <th>Nachname</th>
                    <th>Von</th>
                    <th>Bis</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>
                        <?php echo $result['firstname']; ?>
                    </td>
                    <td>
                        <?php echo $result['lastname']; ?>
                    </td>
                </tr>
            </tbody>
        </table>
EOD;

有人可以帮忙吗。

【问题讨论】:

    标签: php pdf tcpdf heredoc


    【解决方案1】:

    好吧,我以某种方式做到了,但如果有更好的解决方案,请随时发布:)

    代码:

        $loopHereFirstname = '';
        $loopHereLastname  = '';
        foreach($result_set_random_01 as $result_dish_usr_01) {
            $tr_start = '<tr>';
            $tr_end   = '</tr>';
            $td_start = '<td>';
            $td_end   = '</td>';
            $loopHereFirstname .= $result_dish_usr_01['firstname']."\n";
            $loopHereLastname  .= $result_dish_usr_01['lastname']."\n";
        }
    
        $html = <<<EOD
        <table border="1">
            <thead>
                <tr>
                    <th>firstname</th>
                    <th>lastname</th>
                </tr>
            </thead>
            <tbody>
                $tr_start
                    $td_start
                        $loopHereFirstname
                    $td_end
                    $td_start
                        $loopHereLastname
                    $td_end
                $tr_end
            </tbody>
        </table>
    

    EOD;

    【讨论】:

      【解决方案2】:

      如果你想用

      <?php 
           $html =<<<EOD
           <table border="1">
              <thead>
                  <tr>
                      <th>Vorname</th>
                      <th>Nachname</th>
                      <th>Von</th>
                      <th>Bis</th>
                  </tr>
              </thead>
              <tbody>
           EOD;
      
      foreach($result_set as $result) {
      $html.=<<<EOD
      <tr>
          <td>
              {$result['firstname']}
          </td>
          <td>
              {$result['lastname']}
          </td>
      </tr>
      EOD;
      
      }
      
      
      $html .= '</tbody></table>';
      

      【讨论】:

        猜你喜欢
        • 2016-08-24
        • 1970-01-01
        • 1970-01-01
        • 2013-02-24
        • 2013-02-17
        • 2014-10-04
        • 2011-11-26
        • 2014-05-12
        • 1970-01-01
        相关资源
        最近更新 更多