普通网友 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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度