2012-11-14 167 views
-3

我想增加字体大小并向第一个单元格添加蓝色背景。但我无法管理它。如何更改表格字体大小和颜色,Php,Html

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

如何增加字体大小并将蓝色backgorund添加到上表中的第一个单元格?

在此先感谢

+0

样式,背景颜色等,应通过CSS来实现。你之前有过使用CSS的经验吗? – Jrod

+0

php与它无关。你需要CSS,但我没有看到任何。你会如何期待这段代码能够处理字体大小? – GolezTrol

+0

请开始学习CSS。硬编码' '和样式属性在过去的10年中已被证明是不好的做法。 – deceze

回答

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> 
相关问题