In my mysql table i have table that contain points, a want to return number of that table?
Can some one help me?
("select * from liv_sr")
Table contain(id,name,ip,port,*rank*....)
I want to "rank" return in numbers, specifik number Etc.(1,2,3,500)
query[0]['rank']=1200 points=>1 on rank
query[1]['rank']=800 points=>2 on rank
query[2]['rank']=1 points=>500 on rank
You need to use a order by query
$sql="select * from table order by rank desc";
$point =1;
$result = mysql_query($sql);
$tableResult = array();
while($arrayresult =mysql_fetch_array($result))
{
$tableResult[] = array('id'=>$arrayresult['id'],'rank'=>$arrayresult['rank'],'point'=>$point);
$point= $point+1;
}
Don't know if this is already answered, but if you really want to achieve having only one result row, you could have a look at MySQL group_concat. In your example, you could get a result of say for example:
"1200, 600, 500" (comma seperated, ordered by ranked) with
SELECT GROUP_CONCAT(rank ORDER BY rank DESC SEPARATOR ', ') FROM liv_sr GROUP BY 'all'
In php, you could split the result with:
$myArray = explode(',', $result);
Also, note that there's 1024 byte limit on result. If you need more, than simple run:
SET group_concat_max_len = 2048