普通网友 2018-04-16 22:56
浏览 75
已采纳

外部PHP文件到dompdf

I have the following PHP file course.php, which I would like dompdf to render the file. However, when I try to load the external file it tells me headers already loaded.

I have tried some of the tutorials online however when I add inline php the pdf does not render appropriately.

Is there anyway possible to add an external php file?

<?php

include config.php
$course_id= JRequest::getInt('cid');

$dbname = "i2894069_jos2";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT en . * , e.full_name, e.level , c.base_level, s.station
FROM enrolled_students AS en
JOIN employees AS e ON en.student = e.user_id
JOIN stations AS s ON e.station = s.id
JOIN courses_instructed AS ci ON en.pid = ci.ci_id
JOIN courses as c on ci.ci_course = c.id
WHERE en.pid =$course_id
ORDER BY  e.last_name";
$result = $conn->query($sql);
?>

     <style>
.table-fixed thead {
  width: 97%;
}
.table-fixed tbody {
  height: 230px;
  overflow-y: auto;
  width: 100%;
}
.table-fixed thead, .table-fixed tbody, .table-fixed tr, .table-fixed td, .table-fixed th {
  display: block;
}
.table-fixed tbody td, .table-fixed thead > tr> th {
  float: left;
  border-bottom-width: 0;
}
        </style>

 <div class="row">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h4>
            Fixed Header Scrolling Table 
          </h4>
        </div>
        <table class="table table-fixed">
          <thead>
            <tr>
              <th class="col-xs-4">Student</th><th class="col-xs-4">Station</th><th class="col-xs-4">Level</th>
            </tr>
          </thead>
          <tbody>
              <?php while($row = $result->fetch_assoc()) { 
              if($row['level'] == 11){
                     $level = 'Ambulette';
                 }elseif($row['level'] == 2){
                     $level = 'Dispatcher';
                  }elseif($row['level'] == 3){
                     $level = 'EMT';
                 }elseif($row['level'] == 4){
                     $level = 'AEMT';
                 }elseif($row['level'] == 5){
                     $level = 'Paramedic';
                 }elseif($row['level'] == 6){
                     $level = 'IT';
             }elseif($row['level'] == 7){
                     $level = 'RN / Medic';
             }
             else{$level = '';}

             $base_level = $row['base_level'];
             $elevel = $row['level'];

             if($elevel < $base_level){
                 $style = 'class="table-warning"';
             }else{
                 $style = '';
             }

              ?>
            <tr>
              <td class="col-xs-4"><?php echo $row['full_name'] ?></td><td class="col-xs-4"><?php echo $row['station'] ?></td><td class="col-xs-4"><?php echo $level ?></td>
            </tr>
              <?php } ?>
          </tbody>
        </table>
      </div>
  </div>  
  • 写回答

1条回答 默认 最新

  • douxing9228 2018-04-17 01:25
    关注

    If I understand you correctly... what you're looking for is something like this:

    <?php
    
    ob_start();
    require 'yourtemplate.php'; // the one you posted in your question
    $html = ob_get_clean();
    

    Now your HTML is in a variable and you can render it with DOMPDF if you want.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?