mike1313 Posted December 21, 2007 Share Posted December 21, 2007 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 More sharing options...
chigley Posted December 21, 2007 Share Posted December 21, 2007 <?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 More sharing options...
jitesh Posted December 21, 2007 Share Posted December 21, 2007 No need for RANK Feild. Fetch data by Dollor Ascending . Link to comment https://forums.phpfreaks.com/topic/82647-ranking-system-help/#findComment-420346 Share on other sites More sharing options...
chigley Posted December 21, 2007 Share Posted December 21, 2007 No need for RANK Feild. Fetch data by Dollor Ascending . Yeah that's what I thought too.. Link to comment https://forums.phpfreaks.com/topic/82647-ranking-system-help/#findComment-420347 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.