我想在mysql中更改表的最后一行的格式

时间:2016-03-31 08:26:46

标签: php mysql

我正在从MySQL数据库中检索一个表并在HTML表中显示这些记录。但是表格的最后一行显示的是Total值。我想让它变得大胆。只是结果集的最后一行值。怎么做?

<?php
$db_host = 'localhost';
$db_user = 'system';
$db_pwd = 'system';
$database = 'mydb';
$table = 'records';
if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");
if (!mysql_select_db($database))
    die("Can't select database");
// sending query
$result = mysql_query("SELECT * FROM {$table}");
if (!$result) {
    die("Query to show fields from table failed");
}
$fields_num = mysql_num_fields($result);
echo "<table border='1'><tr>";
// printing table headers
for($i=0; $i<$fields_num; $i++)
{
    $field = mysql_fetch_field($result);
    echo "<td style='font-weight:bold'>{$field->name}</td>";
}
echo "</tr>\n";
// printing table rows
while($row = mysql_fetch_row($result))
{
    echo "<tr>";
    // $row is array... foreach( .. ) puts every element
    // of $row to $cell variable
    foreach($row as $cell)
        echo "<td>$cell</td>";
    echo "</tr>\n";
}
mysql_free_result($result);
?>
</body></html>

1 个答案:

答案 0 :(得分:0)

尝试将其放在最后(或在顶部,并不重要):

<style>
  table tr:last-child{
    font-weight: 900;
  }
</style>