所以这是我的代码,但它不起作用,我只是得到了这个
Title Article "; while($row = mysqli_fetch_array($result)) { echo ""; echo "" . $row['Title'] . ""; echo "" . $row['Article'] . ""; echo ""; } echo ""; mysqli_close($con); ?>
有什么想法吗?
<?php
$con=mysqli_connect("localhost","____","____","test_database");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM written");
echo "<table border='1'>
<tr>
<th>Title</th>
<th>Article</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Title'] . "</td>";
echo "<td>" . $row['Article'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
答案 0 :(得分:1)
Tripple检查您的引号是否设置正确。任
echo "<table border='1'>
或
</tr>";
有错误。
您也可以尝试使用echo作为函数(手镯),它应该更容易发现错误: - )
查看生成的标记而不是文本会很有帮助; - )
答案 1 :(得分:0)
你必须这样做:
echo "<table border='1'><tr><th>Title</th><th>Article</th></tr>";
或
echo "<table border='1'>";
echo "<tr>";
echo "<th>Title</th>";
echo "<th>Article</th>";
echo "</tr>";
而不是
echo "<table border='1'>
<tr>
<th>Title</th>
<th>Article</th>
</tr>";