我有一个可能是一个简单的问题,但似乎无法找到指南或解决方案。
当您运行查询并将结果输出到表时,如何将结果放入单独的表中并重复以使其显示如下。
<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
答案 0 :(得分:0)
不确定你想要什么,但我想这可能对你有所帮助
<?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);
?>
答案 1 :(得分:0)
<?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
}
?>