I am trying to write a script that will get TOP ten values from a Table of a certain column.
Here is my code..


$data = mysql_query("SELECT * FROM table
ORDER by rank DESC
LIMIT 10");

while($row = mysql_fetch_array($data))
  echo  $row['id'] ;
  echo "-----";


Here using this while loop i am fetching the data from the Table.This will print the ID of the persons from the table "table" of 10 ten rank.
But what i have to do if i wanna access individual data.For example if i wanna print the 6th data first,then 1st then 4th blah blah......

Thanks ...

6 Years
Discussion Span
Last Post by diafol

If you want to show the random rank data, then use rand() in mysql,

$data = mysql_query("SELECT * FROM table ORDER by rand() LIMIT 10");

You want them in a specific order or random like paul solution?

I *think* paul's will pick any old 10 from the entire table (e.g. 20th, 11th, 1st...)

OR do you mean print the sixth FIELD first, the first field second, the fourth field third etc etc. That's easy.

If you want to randomize the top 10 that's quite easy to do as well.

So give us more info.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.