在echo php表上使用css

时间:2014-04-15 09:57:29

标签: php html mysql css

下面是我的代码,它要求使用php创建一个表,它具有非常基本的样式。

<?php
    $result = mysql_query("SELECT * FROM League ORDER BY Points DESC, Difference DESC, TeamName DESC");
    echo "<style>#size{height:100px;width:340px;overflow-y:scroll;}</style>";
    echo "<table id='size' border='1'>;
            <tr>
            <th>Team</th>
            <th>Played</th>
            <th>Won</th>
            <th>Drawn</th>
            <th>Lost</th>
            <th>For</th>
            <th>Against</th>
            <th>Difference</th>
            <th>Bonus Pts</th>
            <th>Points</th>
            </tr>";

    while($row = mysql_fetch_array($result))
    {
        echo "<tr>";
        echo "<td>" . $row['TeamName'] . "</td>";
        echo "<td>" . $row['Played'] . "</td>";
        echo "<td>" . $row['W'] . "</td>";
        echo "<td>" . $row['L'] . "</td>";
        echo "<td>" . $row['D'] . "</td>";
        echo "<td>" . $row['PF'] . "</td>";
        echo "<td>" . $row['PA'] . "</td>";
        echo "<td>" . $row['Difference'] . "</td>";
        echo "<td>" . $row['BonusPoints'] . "</td>";
        echo "<td>" . $row['Points'] . "</td>";
        echo "</tr>";  
    }
    echo "</table>";
?>

我还创建了一种在我的CSS文件中设置样式的方法,下面是代码

#customers
{
    font-family:"Trebuchet MS", Arial, Helvetica, sans-serif;
    width:100%;
    border-collapse:collapse;
}
#customers td, #customers th 
{
    font-size:1em;
    border:1px solid #98bf21;
    padding:3px 7px 2px 7px;
}
#customers th 
{
    font-size:1.1em;
    text-align:left;
    padding-top:5px;
    padding-bottom:4px;
    background-color:#A7C942;
    color:#ffffff;
}

我知道我的表没有使用表的客户ID,但是当我这样做时它不起作用。所以我在顶部添加了简单的样式,看看它是否有效。任何建议如何让它使用客户造型?谢谢

1 个答案:

答案 0 :(得分:1)

当你宣布你的风格只能在页面的头部宣布..

当你在代码中声明时,以这种方式使用样式..

<?php

echo "<table id='size' style='height:100px;width:340px;overflow-y:scroll;' border='1'>";