Jump to content

[SOLVED] rank user stats


MasterACE14

Recommended Posts

hello,

 

I'm not sure how to go about ranking 3 stats for all users on my website.

 

There is 3 stats stored in the database.

 

Ranks - userID

        - rank

        - strikeActionRank

        - defenceActionRank

        - covertActionRank

 

UserDetails - ID

                - strikeaction

                - defenceaction

                - covertaction

 

Those are the 2 tables and the columns.

 

Need to update the strike/defence/covertActionRank columns in the Ranks table.

rank the users starts from 1 going up. With 1 being the highest strike/defence/covertaction.

And `rank` being strike/defence/covert divided by 3. This update is for all users at once.

 

any help is appreciated.

 

Regards, ACE

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/147882-solved-rank-user-stats/
Share on other sites

Each user has a rank for there strikeaction, defenceaction, coveraction and a overall rank.

 

so the user list with their ranks looks something like....

 

user rank

--------------

user3 1

user56   2

user33   3

user12   4

 

Their strike/defence/covert action rank, is generated based on what their strike/defence/covert action is compared to every other user.

I have 1 script that I use for ranking users `income`, However I've tried changing it so it works for strike/defence/covert action with no luck, and the script doesn't appear to be very efficient.

 

<?php
$incomes = mysql_query("SELECT `miners`,`untrainedSold`,`ID` FROM UserDetails") or die("Error 71");
  
  while($var2 = mysql_fetch_assoc($incomes))
  {
$income = ($var2['miners'] * 25) + ($var2['untrainedSold'] * 10);
$incomearray[$var2['ID']] = $income; 
  }

  arsort($incomearray, SORT_NUMERIC);
  $x = 1;  

  foreach($incomearray AS $ID => $incomerank)
  {
      mysql_query("UPDATE `UserDetails` SET incomerank = '$x' WHERE `ID` = '$ID' && `active` = '1'") or die("Error 81");
      $x++;
  }

this is what I've come up with. However not very efficient.

<?php
$strike = mysql_query("SELECT `strikeaction` FROM `UserDetails` ORDER BY `strikeaction` DESC");

$rank = 0;
while($strike = mysql_fetch_array($strike)) 
{
mysql_query("UPDATE `Ranks` SET `strikeActionRank`='$rank'");
$rank++; 
}

 

any ideas?

got it working now using this method:

<?php
//
// Strike Action
//
$sql = "INSERT INTO `temp_rank` (`id`, `power`) 
SELECT `AllRanks`.`id`,`UserDetails`.`strikeaction`*1 AS `power` FROM `AllRanks`,`UserDetails` WHERE `UserDetails`.`active` = '1' && `UserDetails`.`ID` = `AllRanks`.`id` ORDER BY `power` DESC";
mysql_query($sql) or die('you screwed upv!'.mysql_error());
$sql = "UPDATE `AllRanks`, `temp_rank`
SET `AllRanks`.`id` = `temp_rank`.`id`, `AllRanks`.`SARank` = `temp_rank`.`Rank`
WHERE `AllRanks`.`id` = `temp_rank`.`id`";
mysql_query($sql) or die('you screwed upu!'.mysql_error());
$sql = "TRUNCATE TABLE `temp_rank`";
mysql_query($sql) or die('you screwed upt!'.mysql_error());

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.