MasterACE14 Posted March 4, 2009 Share Posted March 4, 2009 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 Quote Link to comment Share on other sites More sharing options...
trampolinejoe Posted March 4, 2009 Share Posted March 4, 2009 Hello champ, what do you need to update them to? I am sorry I do not understand please explain more clearly. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted March 4, 2009 Author Share Posted March 4, 2009 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. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted March 4, 2009 Share Posted March 4, 2009 I've read that twice and I can see you're explaining what you want to do but I can't see what you're having problems with and want assistance with. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted March 4, 2009 Author Share Posted March 4, 2009 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++; } Quote Link to comment Share on other sites More sharing options...
Yesideez Posted March 4, 2009 Share Posted March 4, 2009 mysql_query("UPDATE `UserDetails` SET incomerank = '$x' WHERE `ID` = '$ID' && `active` = '1'") or die("Error 81"); MySQL doesn't use operators like PHP does - try replacing && with AND. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted March 4, 2009 Author Share Posted March 4, 2009 mysql_query("UPDATE `UserDetails` SET incomerank = '$x' WHERE `ID` = '$ID' && `active` = '1'") or die("Error 81"); MySQL doesn't use operators like PHP does - try replacing && with AND. works both ways. Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted March 4, 2009 Author Share Posted March 4, 2009 bump Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted March 5, 2009 Author Share Posted March 5, 2009 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? Quote Link to comment Share on other sites More sharing options...
gevans Posted March 5, 2009 Share Posted March 5, 2009 When you say it's not very efficient do you mean it doesn't always work? When does it not work, what's your input and excpected output? Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted March 6, 2009 Author Share Posted March 6, 2009 code didn't end up working. really having no luck with this :/ Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted March 6, 2009 Author Share Posted March 6, 2009 bump Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted March 7, 2009 Author Share Posted March 7, 2009 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()); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.