2016-03-31 8 views
0

私はMySQLデータベースからテーブルを取得し、そのレコードをHTMLテーブルに表示しています。しかし、テーブルの最後の行には合計値が表示されます。私はそれを大胆にしたい。結果セットの最後の行の値。それを行う方法?mysqlのテーブルの最後の行のフォーマットを変更したい

<?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>

+0

使用TFOOTとそれ –

+0

にいくつかのCSSを追加テーブルを閉じるタグが表示されません。 '' –

+0

sqlの「SUM」関数を使用して、すべての値を数えます –

答えて

0

最後にこれを入れてみてください(または上部に、本当に重要ではありません):最後の行のための

<style> 
    table tr:last-child{ 
    font-weight: 900; 
    } 
</style> 
関連する問題