[英]How do you separate results? Separate a group of rows into separate tables?
我可能有一個簡單的問題,但似乎找不到指南或解決方案。
當您運行查詢並將結果輸出到表中時,如何將結果放入單獨的表中並重復進行操作,使其顯示如下。
<table>
<tr><td>title</td><td>date</td>
</tr>
<tr><td colspan="2">comment</td>
</tr>
Break table and repeat with next result (sperate tables).
<tr><td>title</td><td>date</td>
</tr>
<tr><td colspan="2">comment</td>
</tr>
</table>
我想要這樣,因此重復整個表而不是最初結果的一部分。
$row)
echo"<tr>";
echo"<td>"; echo $row['title'] . "</td>";
echo"<td>"; echo $row['date'] . "</td>";
echo"</tr>";
echo"<tr>";
echo"<td>"; echo $row['comment'] . "</td>";
echo"</tr>";
}
我舉了這個例子來解釋這個問題。 http://www.thermalzombie.com/temp/example.htm
不確定您到底想要什么,但是我想這可能對您有幫助
<?php
$con=mysqli_connect("example.com","peter","abc123","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Persons");
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
<?php
while($row = mysqli_fetch_array($result))
{ ?>
<table>
<tr><td><?php echo $row['title'];?></td><td><?php echo $row['date'];?></td>
</tr>
<tr><td colspan="2"><?php echo $row['comment'];?></td>
</tr>
</table>
<?php
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.