2013-07-12 33 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。