[英]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.