方法有很多种。1. 临时变量。mysql_query("select @t:=0;");
$result = mysql_query("select *,(@t:=@t+1) row_num from vote order by count desc;");2. 子查询。select *,(select count(*)+1 from vote a where a.count>b.count) row_num from vote b order by b.count desc3. 临时表http://blog.csdn.net/yueliangdao0608/archive/2008/07/30/2737770.aspxMSSQL和Oracle都有对应函数可以取得当前行号。PS:$result不是Array类型,需要这样使用:while($row = mysql_fetch_array($result)){
echo $rows["name"]."当前排名第".$rows["row_num"]."名";
}
$result = mysql_query("select *,(@t:=@t+1) row_num from vote order by count desc;");2. 子查询。select *,(select count(*)+1 from vote a where a.count>b.count) row_num from vote b order by b.count desc3. 临时表http://blog.csdn.net/yueliangdao0608/archive/2008/07/30/2737770.aspxMSSQL和Oracle都有对应函数可以取得当前行号。PS:$result不是Array类型,需要这样使用:while($row = mysql_fetch_array($result)){
echo $rows["name"]."当前排名第".$rows["row_num"]."名";
}
// 先定义一个这样的函数
function mysort($x,$y){
return $x['count']>$y['count'];
}
//然后按你自定义的函数对二位数组排序
uasort($re,"mysort");