1

我怎样才能分配一个唯一的类 id,<tr> 即使我刷新时,id 也需要保持不变,因为我将使用它们来设置表格的样式。

这是我正在使用的代码:

while($row = mysql_fetch_array($result2))
  {
echo "<tr id='centered' class='";  echo "'";   
echo "<td>" . $row['Year_9'] . "</td>";
echo "<td>" . $row['Year_8'] . "</td>";
echo "<td>" . $row['Year_7'] . "</td>";
echo "<td>" . $row['Year_6'] . "</td>";
echo "<td>" . $row['Year_5'] . "</td>";
echo "<td>" . $row['Year_4'] . "</td>";
echo "<td>" . $row['Year_3'] . "</td>";
echo "<td>" . $row['Year_2'] . "</td>";
echo "<td>" . $row['Year_1'] . "</td>";
echo "<td>" . $row['Year_0'] . "</td>";
4

1 回答 1

2

也许使用具有多值类的计数器?

$i = 1;

while($row = mysql_fetch_array($result2))
{
    $secondClass = 'abc' + $i;

    echo "<tr id='centered' class='firstClass $secondClass'>";
    ...
    $i++;
}
于 2012-12-07T21:10:33.117 回答