Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.