Jump to content

ranking system help


mike1313

Recommended Posts

How can I make it so that I can search a table for example the table named donations where it looks through the table and finds the field dollars and updates the same table but a seperate field named rank and updates that field 1 to whatever number for 1 being the person with the highest donation for example.

 

John donated $3400

Bob donated $3000

Sally donated $50

 

So it would update the field named rank to as follows

 

John - 1

Bob - 2

Sally - 3

 

Any help is very greatly appreciated.

Link to comment
https://forums.phpfreaks.com/topic/82647-ranking-system-help/
Share on other sites

<?php

$query = mysql_query("SELECT name FROM table ORDER BY dollars ASC") or die(mysql_error());

$rank = 1;

while(list($name) = mysql_fetch_row($query)) {
$update = mysql_query("UPDATE table SET rank = {$rank} WHERE name = '{$name}'") or die(mysql_error());
$rank++;

echo "Set {$name}'s rank to {$rank}<br />\n";
}

?>

 

Untested :)

Link to comment
https://forums.phpfreaks.com/topic/82647-ranking-system-help/#findComment-420341
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.