MafiaHeros Posted May 18, 2012 Posted May 18, 2012 Hi there, I'm currently working on a Badge/Milestone page, So im listing with this code how many users are above level 5 $result = mysql_query("SELECT * FROM `grpgusers` WHERE `level` > '5'"); $resultmobsters = mysql_num_rows($result); Now i'm trying to list the total mobsters that are below level 5 by using this code $result1 = mysql_query("SELECT * FROM `grpgusers` WHERE `level` < '5'"); $howmany = ($result1); But for that line I get this error, Warning: strrev() expects parameter 1 to be string, resource given in /home/rjd/domains/mafiaheros.com/public_html/classes.php on line 51 Line 51 is my prettynum function: function prettynum($num,$dollar="0") { // Basic send a number or string to this and it will add commas. If you want a dollar sign added to the // front and it is a number add a 1 for the 2nd variable. // Example prettynum(123452838,1) will return $123,452,838 take out the ,1 and it looses the dollar sign. $out=strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,' , strrev( $num ) ) ); if ($dollar && is_numeric($num)){ $out= "$".$out; } return $out; } I'm echo'ing the ranks like this: <td align="right"><i><? echo prettynum($resultmobsters) ?> mobsters have achieved this milestone, <? echo prettynum($howmany) ?> mobsters still need to!</i></td> Would anyone know how I display the amount of grpgusers that are below level 5? Much appreciated :) Quote
sniko Posted May 18, 2012 Posted May 18, 2012 Why use the wildcard '*' if you're just finding out how many users are above level x? Quote
Lithium Posted May 18, 2012 Posted May 18, 2012 (edited) Actually.. that query might not work... grpg has no level field! :) also $result1 = mysql_query("SELECT * FROM `grpgusers` WHERE `level` < '5'"); could become $result1 = mysql_query("SELECT COUNT(`id`) FROM `grpgusers` WHERE `exp` < 'limit_to_level_5_exp'"); Edited May 18, 2012 by Lithium Quote
Spudinski Posted May 18, 2012 Posted May 18, 2012 Actually.. that query might not work... grpg has no level field! :) also $result1 = mysql_query("SELECT * FROM `grpgusers` WHERE `level` < '5'"); could become $result1 = mysql_query("SELECT COUNT(`id`) FROM `grpgusers` WHERE `exp` < 'limit_to_level_5_exp'"); Whilst introducing AS, for associative arrays.. $result1 = mysql_query("SELECT COUNT(`id`) AS `totalUsers` FROM `grpgusers` WHERE `exp` < limit_to_level_5_exp_as_int"); Quote
Lithium Posted May 18, 2012 Posted May 18, 2012 Whilst introducing AS, for associative arrays.. $result1 = mysql_query("SELECT COUNT(`id`) AS `totalUsers` FROM `grpgusers` WHERE `exp` < limit_to_level_5_exp_as_int"); heh thx for correcting it Spud :) i totally forgot that :) Quote
Spudinski Posted May 18, 2012 Posted May 18, 2012 heh thx for correcting it Spud :) i totally forgot that :) Well, your method is indeed valid. But your only index would be at 0, or "COUNT(`id`)" when pulled using mysql_fetch_*. Quote
Primed Posted July 26, 2012 Posted July 26, 2012 I play this game and he has a mod that uses a level field, so your valiant efforts to workaround the absence of are in vain chaps! Quote
Danny696 Posted July 26, 2012 Posted July 26, 2012 By playing a game how do you know he had a mod to do something? To me, it would apear as though it checks how much exp you have, and if you have more than (or equal to) say 100 and less than say 200, you are level 1 etc... Quote
Primed Posted July 27, 2012 Posted July 27, 2012 By playing a game how do you know he had a mod to do something? To me, it would apear as though it checks how much exp you have, and if you have more than (or equal to) say 100 and less than say 200, you are level 1 etc... Because the exp/level system goes a bit like... Exp needed = level * 378 (roughly, it seems to get progressively harder) And I've seen this method used many times, in the classes file, there's a check to seem if current exp is greater than the exp needed and then updates the level field +1. I could be wrong, but it seems to be this method he uses, and it most definitely isn't the basic grpg system Quote
MafiaHeros Posted July 27, 2012 Author Posted July 27, 2012 Because the exp/level system goes a bit like... Exp needed = level * 378 (roughly, it seems to get progressively harder) And I've seen this method used many times, in the classes file, there's a check to seem if current exp is greater than the exp needed and then updates the level field +1. I could be wrong, but it seems to be this method he uses, and it most definitely isn't the basic grpg system Exactly... //Leveling stuff if ($this->exp >= $this->maxexp && $this->exp != 0 && $this->level < 501){ $newlvl = $this->level + 1; $newnerve = $this->maxnerve + 1; $newenergy = $this->maxenergy + 1; $newhp = ($this->level+1) * 50; if($newlvl % 10 == 0 && $newlvl < 500){ $newpoints = rand(2,50); $pts_message = "[+".$newpoints." Points]"; } else { $newpoints = 0; } $expleft = $this->exp - $this->maxexp; Send_Event ($this->id, "You have gained a level! [Level $newlvl] $pts_message", $this->id); RecentGameEvents($this->id, "[-_USERID_-] has gained a level."); $number = isdiv($newlvl, 10); if($number == 1) { $newupgrades = $this->upgradetimes + 1; $result162 = mysql_query("UPDATE `grpgusers` SET `upgradetimes` = '".$newupgrades."' WHERE `id` = '".$this->id."'"); } $result2345 = mysql_query("UPDATE `grpgusers` SET `level`='".$newlvl."', `hp`='".$newhp."', `energy`='".$newenergy."', `nerve`='".$newnerve."', `points`= points + ".$newpoints.", `exp` = '".$expleft."' WHERE `id`='".$this->id."'"); } //End Quote
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.