PHP中的表ID
我试图将anID分配给我用PHP生成的表,但它总是返回一个错误。以下是迄今为止运行良好的完整代码。我只想在表中添加一个“id”,这样我就可以在相关的工作表中将css样式应用到表中PHP中的表ID,php,css,Php,Css,我试图将anID分配给我用PHP生成的表,但它总是返回一个错误。以下是迄今为止运行良好的完整代码。我只想在表中添加一个“id”,这样我就可以在相关的工作表中将css样式应用到表中 <?php $con=mysqli_connect("localhost","<un>","<pw>","monitor"); // Check connection if (mysqli_connect_errno())
<?php
$con=mysqli_connect("localhost","<un>","<pw>","monitor");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM presnationalresults ORDER BY Percentage DESC");
echo "<table border='1'>
<tr>
<th>President</th>
<th>Party</th>
<th>Votes</th>
<th>Percentage</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['PresidentName'] . "</td>";
echo "<td>" . $row['PartyCode'] . "</td>";
echo "<td>" . $row['Votes'] . "</td>";
echo "<td>" . $row['Percentage'] . "</td>";
}
echo "</table>";
mysqli_close($con);
有什么帮助吗?也许我做得不对?请尝试下面的代码块。我添加了表id,并在while循环中关闭了内部
<?php
$con = mysqli_connect("localhost", "<un>", "<pw>", "monitor");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con, "SELECT * FROM presnationalresults ORDER BY Percentage DESC");
echo "<table border='1' id='table-id'>
<tr>
<th>President</th>
<th>Party</th>
<th>Votes</th>
<th>Percentage</th>
</tr>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['PresidentName'] . "</td>";
echo "<td>" . $row['PartyCode'] . "</td>";
echo "<td>" . $row['Votes'] . "</td>";
echo "<td>" . $row['Percentage'] . "</td>";
echo "</tr>"; // you forget close tr
}
echo "</table>";
mysqli_close($con);
我们应该猜到确切的错误吗?还有MySQL代码吗?为什么还要麻烦使用echo输出静态HTML?你所做的只是让你的报价很难正确。对不起。解析错误:语法错误,意外“,你认为这是一段有效的php代码吗?