下面是我的代码,它从mysql表创建一个表,并在它们所在的每个部门下对它们进行排序。现在我一直在尝试的是将department字段(标题)设置为粗体。我试过了
<b>
但它导致错误500,也尝试了
<table style='font-weight:bold'>
但没有运气。简而言之,我会 就像野战部一样大胆。
<?php
$db_host = 'localhost';
$db_user = 'root';
$db_pwd = '******';
$database = 'list';
$table = 'users';
$conn = mysqli_connect($db_host, $db_user, $db_pwd) or die("Connecting to database failed");
mysqli_select_db($conn, $database) or die("Can't select database");
// sending query
$result = mysqli_query($conn, "SELECT name, email, extension, phone, department FROM {$table} ORDER BY department");
if (!$result) {
die("Query to show fields from table failed");
}
echo "<table width='100%' style='font-weight:bold' align='center' border='1'><tr>";
// printing table rows
$temp = "";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
if ($row['department'] != $temp){
echo "<td colspan=\"4\" align=\"center\">" . $row['department'] . "</td></tr>\n<tr>";
$temp = $row['department'];
}
echo "<td>" . $row['name'] . "</td><td>" . $row['email'] . "</td><td>" . $row['extension'] . "</td><td>" . $row['phone'] . "</td>";
echo "</tr>\n";
}
mysqli_free_result($result);
echo "</table>"
?>
答案 0 :(得分:1)
我会将标题重写为以下内容:
echo "<td colspan='4' style='text-align: center; font-weight: bold'>{$row['department']}</td></tr>\n<tr>";
"{$variable}"