1

我从 MySql 表中显示 8 行,我想知道如何在每个结果前面添加数字,例如增量 1.-8. ?

这是我的 MySql 查询行:

$query=mysql_query("SELECT * FROM (SELECT score,pid from score ORDER BY score ASC) As temp GROUP BY temp.pid ORDER BY temp.score ASC LIMIT 8");
4

2 回答 2

3
SELECT @rank := @rank + 1 as row_number, temp.* 
FROM 
(
   SELECT score,pid 
   from score 
   ORDER BY score ASC
) As temp, (select @rank := 0) r 
GROUP BY temp.pid 
ORDER BY temp.score ASC 
LIMIT 8
于 2013-06-14T08:40:21.800 回答
0

在您的PHP中,您可以执行以下操作:

$i = 1;
$query=mysql_query("SELECT * FROM (SELECT score,pid from score ORDER BY score ASC) As temp GROUP BY temp.pid ORDER BY temp.score ASC LIMIT 8");
while($row = mysql_fetch_assoc($query))
{
    echo "<tr>
              <td>". $i ."</td>
              <td>". $row['field'] ."</td>
              <td>". $row['another_field'] ."</td>
              <td>". $row['another_field'] ."</td> 
         </tr>";

    $i += 1;
}
于 2013-06-14T08:41:44.763 回答