我借助此链接使我的表格可排序: LINK
有没有办法让目标列在接受的答案后变成不同的颜色?所以你可以看到,哪个列按哪个排序?
更新更新
这是我的代码:
<?php
$sql = "SELECT * FROM s5_players";
if ($_GET['sort'] == 'matches')
{
$sql .= " ORDER BY matches";
}
elseif ($_GET['sort'] == 'goals')
{
$sql .= " ORDER BY goals";
}
elseif ($_GET['sort'] == 'assists')
{
$sql .= " ORDER BY assists";
}
elseif($_GET['sort'] == 'cards')
{
$sql .= " ORDER BY cards";
}
else
{
$sql .= " ORDER BY goals";
}
$>
和:
<td>Name:</td>
<td><a href="mypage.php?sort=matches">Matches:</td>
<td><a href="mypage.php?sort=goals">Goals:</a></td>
<td><a href="mypage.php?sort=assists">Assists:</a></td>
<td><a href="mypage.php?sort=cards">Cards:</a></td>
进一步向下:
$number = 1;
foreach($results as $row){
echo '
<tr class="statistikker">
<td style="background: #666; text-align: center; color: white; font-weight: bold;">'.$number.'</td>
<td style="padding-left: 5px">'.$row->name.'</td>
<td class="center">'.$row->matches.'</td>
<td class="center">'.$row->goal.'</td>
<td class="center">'.$row->assist.'</td>
<td class="center">'.$row->cards.'</td>
</tr>';
$number++;
};
答案 0 :(得分:0)
以下代码未经过优化,但可以实现您想要实现的目标。
$number = 1;
foreach($results as $row){
echo '
<tr class="statistikker">
<td style="background: #666; text-align: center; color: white; font-weight: bold;">'.$number.'</td>
<td style="padding-left: 5px">'.$row->name.'</td>
<td class="center '.($_GET['sort'] == 'matches' ? 'selected' : '').'">'.$row->matches.'</td>
<td class="center '.((!isset($_GET['sort']) || $_GET['sort'] == 'goal' ? 'selected' : '').'">'.$row->goal.'</td>
<td class="center '.($_GET['sort'] == 'assist' ? 'selected' : '').'">'.$row->assist.'</td>
<td class="center '.($_GET['sort'] == 'cards' ? 'selected' : '').'">'.$row->cards.'</td>
</tr>';
$number++;
};
更新:我在目标 !isset($_GET['sort'])
元素上添加了td
,以反映下面的OP评论目标是标准的排序参数。
它将类selected
添加到相关的td
元素中。然后,您可以为此selected
类创建一个CSS规则,以更改background-color
属性,如下所示:
.selected {
background-color: red;
}