当它现在显示在我的表格中时,它会使用我的数据将对齐中心回显到表格中。我该如何摆脱这个
<?php
mysqli_connect("localhost", "root", "") or die(mysql_error()); //connect to server
mysqli_select_db("first_ db") or die("Can not connect to database");
$query = mysqli_query("Select * from volunteer");
while($row = mysqli_fetch_array($query))
{
echo "<tr>";
echo '<td> align="center">'. $row['StaffID']."</td>";
echo '<td> align="center">'. $row['Name']."</td>";
echo '<td> align="center">'. $row['Address']."</td>";
echo '<td> align="center">'. $row['PhoneNumber']."</td>";
echo '<td> align="center">'. $row['Gender']."</td>";
echo '<td> align="center">'. $row['StaffStatus']."</td>";
echo '<td> align="center"><a hred="Edit.php">Edit</a> </td>'
echo '<td> align="center"><a href="Delete.php">Delete</a> </td>';
echo "</tr>";
}
?>
</table>
</body>
</html>
答案 0 :(得分:0)
首先,总是将你的会话放在任何其他代码之前
第二
mysql_connect
mysql_query
mysql_select_db
mysql_fetch_array
已被弃用
mysqli_connect
mysqli_query
mysqli_select_db
mysqli_fetch_array
第三,你的桌子没有
tbody or thead
用echo
替换打印答案 1 :(得分:0)
<?php
$servername = "localhost";
$username = "username";
$password = "";
$dbname = "first_db";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "Select * from volunteer";
$query = mysqli_query($conn, $sql);
if (mysqli_num_rows($query) > 0) {
while ($row = mysqli_fetch_assoc($query)) {
echo "<tr>";
echo "<td> align=\"center\">" . $row['StaffID'] . "</td>";
echo "<td> align=\"center\">" . $row['Name'] . "</td>";
echo "<td> align=\"center\">" . $row['Address'] . "</td>";
echo "<td> align=\"center\">" . $row['PhoneNumber'] . "</td>";
echo "<td> align=\"center\">" . $row['Gender'] . "</td>";
echo "<td> align=\"center\">" . $row['StaffStatus'] . "</td>";
echo "<td> align=\"center\"><a hred=\"Edit.php?id=" . $row['StaffID'] . "\">Edit</a> </td>";
echo "<td> align=\"center\"><a href=\"Delete.php?id=" . $row['StaffID'] . "\">Delete</a> </td>";
echo "</tr>";
}
} else {
echo "no results";
}
?>
</table>
</body>
</html>
答案 2 :(得分:-1)
将Print
替换为echo
echo "<tr>";
echo '<td> align="center">'. $row['StaffID]."</td>";
echo '<td> align="center">'. $row['Name']."</td>";
echo '<td> align="center">'. $row['Address']."</td>";
echo '<td> align="center">'. $row['/PhoneNumber']."</td>";
echo '<td> align="center">'. $row['Gender']."</td>";
echo '<td> align="center">'. $row['StaffStatus']."</td>";
echo '<td> align="center"><a hred="Edit.php">Edit</a> </td>'
echo '<td> align="center"><a href="Delete.php">Delete</a> </td>';
echo "</tr>";