Php I';我试图根据行值将一个表拆分为多个表,对于行值a中的每一个更改,表都会中断,并开始一个新表
我是从mysql查询中提取的。目标是在行值a更改时中断表,并创建一个新表。到目前为止,我能够填充该表,但在$row a值更改后,我无法打破该表并启动新的表。有什么建议吗Php I';我试图根据行值将一个表拆分为多个表,对于行值a中的每一个更改,表都会中断,并开始一个新表,php,mysql,while-loop,datatables,Php,Mysql,While Loop,Datatables,我是从mysql查询中提取的。目标是在行值a更改时中断表,并创建一个新表。到目前为止,我能够填充该表,但在$row a值更改后,我无法打破该表并启动新的表。有什么建议吗 <?php $previousCategory = ''; //empty variable $run = 0; // counter while($row = mssql_fetch_array($this->query)) { $run++;
<?php
$previousCategory = ''; //empty variable
$run = 0; // counter
while($row = mssql_fetch_array($this->query))
{
$run++;
if ($previousCategory !== $row['A'] || $run == 0 ) {
//close the table
if ($run != 0) {
echo "</tbody></table>";
} else {
echo ".$row['A'].";
}
?>
<table id="Table">
<thead>
<caption><?php echo $row['A'] ?></caption>
<tr class="data">
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
<th>E</th>
<th>F</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mssql_fetch_assoc($this->query)) {
echo "<tr>";
echo "<td>".$row['A']."</td>";
echo "<td>".$row['B']."</td>";
echo "<td>".$row['C']."</td>";
echo "<td>".$row['D']."</td>";
echo "<td>".$row['E']."</td>";
echo "<td>".$row['F']."</td>";
echo "</tr>";
}
} // closes if. Starts a new table.
} // Close the while statement
?>
</tbody>
</table>
A.
B
C
D
E
F
您从不更新$previousCategory
。在循环的底部,您应该有$previousCategory=$row['A']
。另外,你的“中断”代码应该在while/fetch循环中,因为在你进行中断测试的时候,你实际上还没有开始从数据库中获取任何东西,而且永远不会中断任何东西。除了@MarcB所说的,你还使每个表具有相同的ID,并且ID在一个页面中必须是唯一的。