如何在具有特定颜色的前10个条目的表格中显示记录


How to display records in table with top 10 enteries with specific colour

我正在尝试用特定颜色的显示表中前10个条目的记录

我的查询仅用于参考

$sqlsum=mysql_query("SELECT `userid`, SUM(`points`) as `total` FROM 
    `tablename` GROUP BY `userid` ORDER BY total DESC LIMIT 10");

下面的代码显示了一个简单的表格,我需要显示前10个条目颜色不同的表格[蓝色]。。其余部分保持不变[白色背景]。即前10名可以是蓝色,其余可以是白色。下面是我用来显示记录的代码。

<?php 
      while($row = mysql_fetch_array($sqlsum)) 
      {
echo "<tr> ";
     echo "<td>" .$row[userid] . "</td>";
     echo "<td>" .$row[total] . "</td>";
     }
echo "</tr> " ;
      ?>

我有这个表格结构作为样本。我想用这个代码。表需要相同,但我没有找到逻辑,如何构建表采用这种结构的

     <table>
    <thead><tr><td colspan="2"><center>Prizes</center></td></tr><tr>
<th>Position</center></th><th><center>Prize</center></th></tr></thead>
    <tbody><tr><td>1st</td><td>0.0$</td></tr>
    <tr class="alt"><td>2nd</td><td>0.0$</td></tr>
    <tr><td>3rd</td><td>0.0$</td></tr>
    <tr class="alt"><td>4th</td><td>0.0$</td></tr>
    <tr><td>5th</td><td>0.0$</td></tr>
    </tbody>
    </table>

删除提取所有数据的限制10:

$sqlsum=mysql_query("SELECT `userid`, SUM(`points`) as `total` FROM 
 `tablename` GROUP BY `userid` ORDER BY total DESC");

php:

<?php 
$i=1;
while($row = mysql_fetch_array($sqlsum))
{
     echo "<tr ".(($i <= 10) ? "bgcolor='blue'" : '')'."> "; 
     // Apply attrinute bgcolor for backgroung color
     echo "<td>" .$row[userid] . "</td>";
     echo "<td>" .$row[total] . "</td>";
     echo "</tr>";
     $i++;
}
?>

设置一个指标变量来指向它。

<?php 
      $rowNumber = 0;
      while($row = mysql_fetch_array($sqlsum)) 
      {
         if ($rowNumber < 10)
         {
             echo "<tr class='"alt'"> ";
         }
         else
         {
             echo "<tr> ";
         }
         echo "<td>" .$row[userid] . "</td>";
         echo "<td>" .$row[total] . "</td>";
         echo "</tr> " ;
         $rowNumber++;
     }
?>