2013-07-12 32 views
0

我目前正在從mySQL中獲取表格的項目,這些表格顯示在html表格中。下面你可以看到代碼。將自定義字體應用於PHP中的表格單元格echo

if (mysql_num_rows($result) > 0) { 
    // yes 
    // print them one after another 
    echo "<table cellpadding=1 border=1 width=100%>"; 
    while($row = mysql_fetch_row($result)) { 
     echo "<tr>"; 
       echo "<td>"."<center>".$row[0]."</center>"."</td>"; 

     echo "<td>" .$row[2]."</td>"; 
     echo "<td>" .$row[1]."</td>"; 
     echo "<td>" .$row[3]."</td>"; 
     echo "</tr>"; 
    } 
    echo "</table>"; 
} 

我需要將其更改爲

if (mysql_num_rows($result) > 0) { 
    // yes 
    // print them one after another 
    echo "<table cellpadding=1 border=1 width=100%>"; 
    while($row = mysql_fetch_row($result)) { 
     echo "<tr>"; 
       echo "<td>"."<center>".$row[0]."</center>"."</td>"; 

     echo "<td>" .$row[2]."</td>"; 
     echo "<td>" .$row[1]."</td>"; 
     echo "<td><font face="Georgia, Times New Roman, Times, serif">" .$row[3]."</font></td>";  
     echo "</tr>"; 
    } 
    echo "</table>"; 
} 

當我這樣做是拋出回的錯誤。我這樣做,所以用戶看到我有一個字體的條形碼。

我做錯了嗎?還是有另一種更好的方法。

感謝 瑞安

+0

最新錯誤,你可以在這裏發佈? –

+0

請編輯您的問題,以包括錯誤 – RedEyedMonster

回答

0

改變「,以」人臉:

echo "<td><font face='Georgia, Times New Roman, Times, serif'>" .$row[3]."</font></td>"; 

,而不是內嵌字體,你應該使用CSS類或ID還(檢查此例如CSS類的Applying css to a php table

0

嘗試

echo "<td><font face='Georgia, Times New Roman, Times, serif'>" .$row[3]."</font></td>"; 
+0

謝謝你。有效。 –

0

OMG ..不要使用font標籤。它從HTML 4.01開始已被棄用,並且在HTML 5中不可用。錯誤來自不正確的轉義。

echo "<td><font face=\"Georgia, 'Times New Roman', Times, serif\">" ... 

但請使用一個類,並使用CSS做樣式。

echo "<td class=\"font-georgia\">... 

而且在CSS:

.font-georgia { 
    font-family: Georgia, 'Times New Roman', Times, serif; 
} 

注意引號'Times New Roman'因爲它有空格。

center標籤相同。改爲使用text-align:center CSS。