2012-11-14 172 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> 
相關問題