ถึงจะเป็นยุคที่เราใช้ div เป็นหลักแล้วแต่ในบางเนื้อหา table ยังมีความจำเป็นอยู่
ในกรณีที่ table มีหลาย column และเราใช้ $tp->sub(); ถ้าข้อมูลไม่ครบจะไม่ถูกปิด มาดูวิธีแก้ก้น
ผลการทำงาน (ปิด tag “ไม่” ถูกต้อง)
ผลการทำงาน (ปิด tag ถูกต้อง)
*ต้อง view source คู่กันไปด้วย
สามารถทดลองเปลี่ยน item=5 เป็นจำนวนที่ต้องการได้
_tp_table.html
<!DOCTYPE html>
<html>
<head>
<title>$title</title>
<link rel="stylesheet" href="module/bootstrap/bootstrap.min.css">
</head>
<body>
<div class="container">
<h3>$title</h3>
<table class="table table-bordered">
<colgroup>
<col class="col-sm-3">
<col class="col-sm-3">
<col class="col-sm-3">
<col class="col-sm-3">
</colgroup>
<!--SiXhEaD:data-->
<!--sub:1-->
<tr>
<td>$name</td><!--/sub:1-->
<!--sub:2-->
<td>$name</td><!--/sub:2-->
<!--sub:3-->
<td>$name</td><!--/sub:3-->
<!--sub:4-->
<td>$name</td>
</tr>
<!--/sub:4-->
<!--/SiXhEaD:data-->
</table>
</div>
<script src="module/jquery/jquery.min.js"></script>
<script src="module/bootstrap/bootstrap.min.js"></script>
</body>
</html>
table.php
<?php
require 'module/SiXhEaD.Template.php';
$item = (int) $_GET['item'];
$fix = (int) $_GET['fix'];
if (!$item) {
$item = 5;
}
if ($item > 100) {
$item = 100;
}
$tp = new Template('_tp_table.html');
$title = 'วิธีการเติม table ให้เต็ม';
$tp->block('data');
$tp->sub(4);
for ($no = 1; $no <= $item; $no++) {
$name = $no;
$tp->apply();
}
if ($fix) {
if ($tp->getCurrentSub() != 1) {
for ($no = $tp->getCurrentSub(); $no <= 4; $no++) {
$name = '';
$tp->apply();
}
}
}
$tp->display();
exit;