Current location: Hot Scripts Forums » Programming Languages » PHP » how to rank mysql database entries


how to rank mysql database entries

Reply
  #1 (permalink)  
Old 12-21-04, 07:30 PM
robbydweb robbydweb is offline
Newbie Coder
 
Join Date: Dec 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
how to rank mysql database entries

I have a mysql database of entries with one column having a number value called score.
is there sql command or a way to take the top 5 scores from the database and display them into an array?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 12-21-04, 11:46 PM
xtremenw xtremenw is offline
Newbie Coder
 
Join Date: Dec 2004
Location: Tacoma, WA
Posts: 69
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by robbydweb
I have a mysql database of entries with one column having a number value called score.
is there sql command or a way to take the top 5 scores from the database and display them into an array?
"select value, score from table order by score desc limit 0,4"

try the above. i am not very good with asc or desc, so you might need to switch it. Also, 0,4 should show 5 entries... Also, replace value & score & table with the correct information for your sql table.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 12-22-04, 01:42 PM
James Talbot James Talbot is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Its quite easy an easy way to do what i think you want.

PHP Code:



$sql = mysql_query("SELECT * FROM table ORDER BY something");

// Set rank to 0

$rank = 0;

while($data = mysql_fetch_array($sql)) {


$rank = $rank++;

?>

<p><?=$rank;?></p>
<p><?=$data['username'];?></p>

<?
}
?>
Obviously update that so it suits your needs.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Form to update a MySQL database? Scoobler PHP 9 09-04-08 02:41 AM
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 03:22 AM
MySQL: Can it handle 1 million + entries? archangel PHP 3 08-16-04 04:52 AM
Help with echo'ing rows of (td's) from database entries paulj000 PHP 6 04-20-04 10:32 AM
Error while creating database (Errornumber 2002: "Can't connect to local MySQL server lylesback2 PHP 5 04-11-04 02:37 PM


All times are GMT -5. The time now is 07:17 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.