如何获取 HTML 表作为 PHP 变量?
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个代码。
干杯!
Try this code.
Cheers!
也许heredoc syndax会有所帮助:
http://www.phpf1.com/tutorial/php -heredoc-syntax.html
Maybe heredoc syndax would help:
http://www.phpf1.com/tutorial/php-heredoc-syntax.html