如何更改表字体大小和颜色,Php,Html

时间:2012-11-14 15:23:13

标签: php html-table

我正在尝试增加字体大小并为第一个单元格添加蓝色背景,但我无法管理它。

// sending query
$result = mysql_query("SELECT `UserName`,`UserScore` FROM {$table} ORDER BY `UserScore` DESC");
if (!$result) {
    die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);


echo "<table border='1' align='center'><tr>";
// printing table headers
//for($i=0; $i<$fields_num; $i++)
//{
  //  $field = mysql_fetch_field($result);
    echo "<td>Name &nbsp;&nbsp;&nbsp;&nbsp;</td>";
    echo "<td>Score &nbsp;&nbsp;&nbsp;&nbsp;</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);

如何增加字体大小并为上表中的第一个单元格添加蓝色背景?

1 个答案:

答案 0 :(得分:1)

希望这有帮助!

<?php
$result = mysql_query("SELECT `UserName`,`UserScore` FROM {$table} ORDER BY `UserScore` DESC");
if (!$result) {
    die("Query to show fields from table failed");
}

$fields_num = mysql_num_fields($result);


echo "<table border='1' align='center'><tr>";
// printing table headers
//for($i=0; $i<$fields_num; $i++)
//{
  //  $field = mysql_fetch_field($result);
    echo "<td>Name &nbsp;&nbsp;&nbsp;&nbsp;</td>";
    echo "<td>Score &nbsp;&nbsp;&nbsp;&nbsp;</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
    $i = 0;
    foreach($row as $cell)
    {
       if($i == 0)
           $class = "class = 'backg'";
       else
           $class = "class = ''";
        echo "<td ".$class.">$cell</td>";

     $i++;
    }
    echo "</tr>\n";
}
mysql_free_result($result);
?>

这里的样式

<style>
.backg{background:blue;font-size:18px;}
</style>