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

Link to comment
Share on other sites

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++;
  }

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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());

Link to comment
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.