如何在输出上添加一些css代码来回显?

时间:2016-05-23 00:26:35

标签: php html css database echo

并且我希望文件的单元文件名称大小等为蓝色,并且该行是悬停的不同颜色! 当我用鼠标在行上交叉时,我想改变颜色。 我尝试用css和所有来自互联网的toutorials。 标题我想成为一种颜色。 但没有运气......任何想法?

抱歉我的英文!

祝你好运!     

    // connect to the database
    include('database.php');

    // number of results to show per page
    $per_page = 3;

    // figure out the total pages in the database
    $result = mysql_query("SELECT * FROM files");
    $total_results = mysql_num_rows($result);
    $total_pages = ceil($total_results / $per_page);

    // check if the 'page' variable is set in the URL (ex: view-paginated.php?page=1)
    if (isset($_GET['page']) && is_numeric($_GET['page']))
    {
        $show_page = $_GET['page'];

        // make sure the $show_page value is valid
        if ($show_page > 0 && $show_page <= $total_pages)
        {
            $start = ($show_page -1) * $per_page;
            $end = $start + $per_page; 
        }
        else
        {
            // error - show first set of results
            $start = 0;
            $end = $per_page; 
        }       
    }
    else
    {
        // if page isn't set, show first set of results
        $start = 0;
        $end = $per_page; 
    }

    // display pagination

    for ($i = 1; $i <= $total_pages; $i++)
    {
        echo "<a href='view.php?page=$i'>$i</a> ";
    }
    echo "</p>";

    // display data in table
    echo "<table class=' tablesorter' cellpadding='1'>";
    echo 
    "<tr><th>File name</th> <th>Size of file</th> <th>Date added</th> <th>Hits/Downloads</th<th>Download file</th>
    </tr>";

    // loop through results of database query, displaying them in the table 
    for ($i = $start; $i < $end; $i++)
    {
        // make sure that PHP doesn't try to show results that don't exist
        if ($i == $total_results) { break; }

        // echo out the contents of each row into a table
        echo "<tr>";
        echo '<td>' . mysql_result($result, $i, 'file_id') . '</td>';
        echo '<td>' . mysql_result($result, $i, 'file_name') . '</td>';
        echo '<td>' . mysql_result($result, $i, 'file_category') . '</td>';
        echo '<td>' . mysql_result($result, $i, 'file_date') . '</td>';
        echo '<td>' . mysql_result($result, $i, 'file_version') . '</td>';
        echo '<td>' . mysql_result($result, $i, 'file_link') . '</td>';

        echo "</tr>"; 
    }
    // close table>


    // pagination

?

&GT;

1 个答案:

答案 0 :(得分:1)

为什么不在行中添加类?像这样:

// display data in table
echo "<table class=' tablesorter' cellpadding='1'>";
echo 
"<tr class='tableHeadRow'><th>File name</th> <th>Size of file</th> <th>Date added</th> <th>Hits/Downloads</th<th>Download file</th>
</tr>";

// loop through results of database query, displaying them in the table 
for ($i = $start; $i < $end; $i++)
{
    // make sure that PHP doesn't try to show results that don't exist
    if ($i == $total_results) { break; }

    // echo out the contents of each row into a table
    echo "<tr class='tableRow'>";
    echo '<td>' . mysql_result($result, $i, 'file_id') . '</td>';
    echo '<td>' . mysql_result($result, $i, 'file_name') . '</td>';
    echo '<td>' . mysql_result($result, $i, 'file_category') . '</td>';
    echo '<td>' . mysql_result($result, $i, 'file_date') . '</td>';
    echo '<td>' . mysql_result($result, $i, 'file_version') . '</td>';
    echo '<td>' . mysql_result($result, $i, 'file_link') . '</td>';

    echo "</tr>"; 
}
// close table>

然后在css中为这两个类.tableHeadRow.tableRow

设置样式