我正在使用以下代码来显示mysql数据。问题是在以HTML格式显示数据时,数据显示在一行中而不会被包装。
UseSqlServer
请帮我解释一下代码。
答案 0 :(得分:0)
您缺少关闭<tr>
标记,因此,您的所有数据都在同一行。
while($res = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>".$res['topic']."</td>";
echo "<td>".$res['issue']."</td>";
echo "<td>".$res['solution']."</td>";
echo "<td><div align='center'><a href=\"edit.php?id=$res[id]\">Edit</a> | <a href=\"delete.php?id=$res[id]\" onClick=\"return confirm('Are you sure you want to delete?')\">Delete</a></td>";
echo "</tr>"; // << close <tr> tag
}
答案 1 :(得分:0)
使用<br>
打破该行。
答案 2 :(得分:0)
首先,您必须打印<table>
才能创建表格
echo "<table>";
.
.
.
.
echo "</table>";
without table tag<br>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
<br>
with table taaag
<table>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
</table>
&#13;
答案 3 :(得分:0)
试试这个演示,为演示使用数组而不是表数据,
<?php
$data=array(array("id"=>1,"topic"=>"php","issue"=>"var
error","solution"=>"declare
first"),array("id"=>2,"topic"=>"asp","issue"=>"var error
validatipn","solution"=>"validate js add"));
?>
<table border="1">
<thead>
<tr><th>topic</th><th>issue</th><th>solution</th><th>Action</th></tr>
</thead>
<tbody>
<?php
foreach($data as $res)
{
echo "<tr>";
echo "<td>".$res['topic']."</td>";
echo "<td>".$res['issue']."</td>";
echo "<td>".$res['solution']."</td>";
echo "<td><div align='center'><a href=\"edit.php?id=$res[id]\">Edit</a> |
<a
href=\"delete.php?id=$res[id]\" onClick=\"return confirm('Are you sure you
want to delete?')\">Delete</a></td></tr>";
}
?>
</tbody>
</table>