如何获取 HTML 表作为 PHP 变量?

发布于 2024-12-23 10:00:47 字数 2381 浏览 1 评论 0原文

我正在使用 DOMpdf 创建 pdf 文件。要打印下表,我必须将其作为变量获取,然后将其发送到我的控制器。就像 $value = "Some value(在这个地方我想要下表) "; 但在这种情况下,我不确定当你有一些 PHP 脚本时如何将整个表放入变量中填充数据。

请帮忙。

   <?php if(count($records) > 0) { ?>
            <h1> Batch Name: <?php echo "$batchname";?> </h1>
            <table id="table1" class="gtable sortable">
            <thead>
                    <tr>
                        <th>S.N</th>
                        <th>Student ID</th>
                        <th>Exam Date</th>
                        <th>Exam Type</th>
                        <th>Subject</th>
                        <th>Total Mark</th>
                        <th>Highest Mark</th>
                        <th>Obtained Mark</th>
                        <th>GPA</th>
                        <th>Grade</th>
                        <th>Status</th>

                    </tr>
            </thead>
            <tbody>
             <?php $i = $this->uri->segment(3) + 0; foreach ($records as $row){ $i++; ?>


                    <tr>
                        <td><?php echo $i; ?>.</td>

                        <td><a href="<?php echo base_url(); ?>viewbatch/get/<?php echo $row['studentid']; ?>"><?php echo $row['studentid'];?></a></td>
                        <td><?php echo $row['examdate'];?></td>
                        <td><?php echo $row['examtype'];?></td>

                        <td><?php echo $row['subject'];?></td>
                        <td><?php echo $row['totalmark'];?></td>

                        <td><?php echo $row['highestmark'];?></td>
                        <td><?php echo $row['obtainedmark'];?></td>

                        <td><?php echo $row['gradepoint'];?></td>
                        <td><?php echo $row['grade'];?></td>
                        <td><?php echo $row['status'];?></td>



                    </tr>
            <?php  } ?>

            </tbody>
            </table>

I am using DOMpdf to create pdf files. To print the following table I have to get it as a variable and then send it to my controller. just like $value = "Some value(in this place I want the following table) "; But here in this case I am not sure how get this entire table inside a variable when you have some PHP script to populate data.

Please help.

   <?php if(count($records) > 0) { ?>
            <h1> Batch Name: <?php echo "$batchname";?> </h1>
            <table id="table1" class="gtable sortable">
            <thead>
                    <tr>
                        <th>S.N</th>
                        <th>Student ID</th>
                        <th>Exam Date</th>
                        <th>Exam Type</th>
                        <th>Subject</th>
                        <th>Total Mark</th>
                        <th>Highest Mark</th>
                        <th>Obtained Mark</th>
                        <th>GPA</th>
                        <th>Grade</th>
                        <th>Status</th>

                    </tr>
            </thead>
            <tbody>
             <?php $i = $this->uri->segment(3) + 0; foreach ($records as $row){ $i++; ?>


                    <tr>
                        <td><?php echo $i; ?>.</td>

                        <td><a href="<?php echo base_url(); ?>viewbatch/get/<?php echo $row['studentid']; ?>"><?php echo $row['studentid'];?></a></td>
                        <td><?php echo $row['examdate'];?></td>
                        <td><?php echo $row['examtype'];?></td>

                        <td><?php echo $row['subject'];?></td>
                        <td><?php echo $row['totalmark'];?></td>

                        <td><?php echo $row['highestmark'];?></td>
                        <td><?php echo $row['obtainedmark'];?></td>

                        <td><?php echo $row['gradepoint'];?></td>
                        <td><?php echo $row['grade'];?></td>
                        <td><?php echo $row['status'];?></td>



                    </tr>
            <?php  } ?>

            </tbody>
            </table>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倦话 2024-12-30 10:00:47

试试这个代码。

<?php
ob_start(); 
if(count($records) > 0) { ?>
            <h1> Batch Name: <?php echo "$batchname";?> </h1>
            <table id="table1" class="gtable sortable">
            <thead>
                    <tr>
                        <th>S.N</th>
                        <th>Student ID</th>
                        <th>Exam Date</th>
                        <th>Exam Type</th>
                        <th>Subject</th>
                        <th>Total Mark</th>
                        <th>Highest Mark</th>
                        <th>Obtained Mark</th>
                        <th>GPA</th>
                        <th>Grade</th>
                        <th>Status</th>

                    </tr>
            </thead>
            <tbody>
             <?php $i = $this->uri->segment(3) + 0; foreach ($records as $row){ $i++; ?>


                    <tr>
                        <td><?php echo $i; ?>.</td>

                        <td><a href="<?php echo base_url(); ?>viewbatch/get/<?php echo $row['studentid']; ?>"><?php echo $row['studentid'];?></a></td>
                        <td><?php echo $row['examdate'];?></td>
                        <td><?php echo $row['examtype'];?></td>

                        <td><?php echo $row['subject'];?></td>
                        <td><?php echo $row['totalmark'];?></td>

                        <td><?php echo $row['highestmark'];?></td>
                        <td><?php echo $row['obtainedmark'];?></td>

                        <td><?php echo $row['gradepoint'];?></td>
                        <td><?php echo $row['grade'];?></td>
                        <td><?php echo $row['status'];?></td>



                    </tr>
            <?php  } ?>

            </tbody>
            </table>
<?php
$output = ob_get_clean();
 ?>

干杯!

Try this code.

<?php
ob_start(); 
if(count($records) > 0) { ?>
            <h1> Batch Name: <?php echo "$batchname";?> </h1>
            <table id="table1" class="gtable sortable">
            <thead>
                    <tr>
                        <th>S.N</th>
                        <th>Student ID</th>
                        <th>Exam Date</th>
                        <th>Exam Type</th>
                        <th>Subject</th>
                        <th>Total Mark</th>
                        <th>Highest Mark</th>
                        <th>Obtained Mark</th>
                        <th>GPA</th>
                        <th>Grade</th>
                        <th>Status</th>

                    </tr>
            </thead>
            <tbody>
             <?php $i = $this->uri->segment(3) + 0; foreach ($records as $row){ $i++; ?>


                    <tr>
                        <td><?php echo $i; ?>.</td>

                        <td><a href="<?php echo base_url(); ?>viewbatch/get/<?php echo $row['studentid']; ?>"><?php echo $row['studentid'];?></a></td>
                        <td><?php echo $row['examdate'];?></td>
                        <td><?php echo $row['examtype'];?></td>

                        <td><?php echo $row['subject'];?></td>
                        <td><?php echo $row['totalmark'];?></td>

                        <td><?php echo $row['highestmark'];?></td>
                        <td><?php echo $row['obtainedmark'];?></td>

                        <td><?php echo $row['gradepoint'];?></td>
                        <td><?php echo $row['grade'];?></td>
                        <td><?php echo $row['status'];?></td>



                    </tr>
            <?php  } ?>

            </tbody>
            </table>
<?php
$output = ob_get_clean();
 ?>

Cheers!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文