【问题标题】:How to change Table Font Size and Color, Php ,Html [closed]如何更改表格字体大小和颜色,Php,Html [关闭]
【发布时间】:2018-07-10 16:12:38
【问题描述】:

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

// 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);

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

【问题讨论】:

  • 文本样式、背景颜色等应通过 CSS 完成。你以前有过使用 CSS 的经验吗?
  • php 与它无关。您将需要 CSS,但我没有看到任何这些。您希望这段代码如何处理字体大小?
  • 请开始学习 CSS。在过去的 10 年里,硬编码 &amp;nbsp; 和样式属性已被证明是一种不好的做法。

标签: php html-table


【解决方案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>

【讨论】:

    猜你喜欢
    • 2013-11-09
    • 2016-07-03
    • 1970-01-01
    • 2019-09-24
    • 2018-06-05
    • 1970-01-01
    • 2017-10-30
    • 2015-06-09
    • 1970-01-01
    相关资源
    最近更新 更多