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

<?php
include("../inc/db.php")

$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 ...

Recommended Answers

All 2 Replies

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");
Member Avatar for diafol

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.