Reecey12345 Posted May 19, 2014 Share Posted May 19, 2014 Well, I'm a little stuck here with how i'm going to create a little add-on. Going to release it as a free module once its done if i get this done. if($r['level'] == ???) { $crown="<img src='crown_gold.png' alt='1st Position' title='1st Position' />"; I written this code, then had to think, but how am I to find the highest level, I want this to display on viewuser, userlist and usersonline. Any help with how I would do this, I also was to create it for a 2nd and 3rd position. Quote Link to comment Share on other sites More sharing options...
Samurai Legend Posted May 19, 2014 Share Posted May 19, 2014 (edited) $rowSQL = $db->query( "SELECT MAX( level ) AS top FROM `users`;" ); $row = mysql_fetch_array( $rowSQL ); $largestNumber = $row['top']; if($row['top']) { $crown="<img src='crown_gold.png' alt='1st Position' title='1st Position' />"; } Something like that will bring the first best player... Or $q = $db->query("SELECT username,level FROM users ORDER BY level DESC LIMIT 2,1"); $r = $db->fetch_row($q); if($r['level']) { $crown="<img src='crown_silver.png' alt='2nd Position' title='2nd Position' />"; } Something like that will bring the second best player... I am not sure though. Edited May 19, 2014 by Samurai Legend Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted May 19, 2014 Share Posted May 19, 2014 Hmm never actually thought about this but let me see what I can possibly do here and to note it's not tested since I'm on my phone so some may be pseudo. $sql = "select userid, level from users order by level desc limit 0,3"; $query = $db->query($sql); $i = 1; while($go = $db->fetch_row($query) { if(in_array($go["userid"],$r["userid"])) { if($i == 1) { //this would be the highest level player } else if($i == 2) { //second place } else { //third place } } $i++; } Now I am sure there is a much better method than that but ehh, oh well Quote Link to comment Share on other sites More sharing options...
Reecey12345 Posted May 19, 2014 Author Share Posted May 19, 2014 Yeah I have a ton of ideas in my head that nobody has created yet, its just creating them now which isn't so simple for a guy of my coding abilitys, but im learning. Something simple as this is very effective. Competitiveness comes a lot more into the game with this :-) Anyhow so this is what needs to be done? Ill give it a try anyhow $sql = "select userid, level from users order by level desc limit 0,3"; $query = $db->query($sql); $i = 1; while($go = $db->fetch_row($query) { if(in_array($go["userid"],$r["userid"])) { if($i == 1) { $crown="<img src='crown_gold.png' alt='1st Position' title='1st Position' />"; } else if($i == 2) { $crown="<img src='crown_silver.png' alt='2nd Position' title='2nd Position' />"; } else { $crown="<img src='crown_bronze.png' alt='3rd Position' title='3rd Position' />"; } } $i++; } Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted May 19, 2014 Share Posted May 19, 2014 Yeah it can probably be shortened up using some ternary operators instead of a plethora of nested ifs but soo hard on the mobile tele Quote Link to comment Share on other sites More sharing options...
Reecey12345 Posted May 19, 2014 Author Share Posted May 19, 2014 A few errors within that bit of code, going to hit the pillow and see if I can get this sorted tomorrow Quote Link to comment Share on other sites More sharing options...
wrux Posted May 19, 2014 Share Posted May 19, 2014 What is being overlooked here is the ordering. If numerous players have the same level there will be some ambiguity, therefore it would require ordering multiple fields maybe? I'm not gonna post any PHP but this query would give the top three without any same-level ambiguity: SELECT `username`, `level` FROM `users` ORDER BY `level` DESC, `exp` DESC LIMIT 0,3 Quote Link to comment Share on other sites More sharing options...
Jason-x Posted May 19, 2014 Share Posted May 19, 2014 i already have this, the way i did mine was showing the top 3 by total EXP, that way says the top lvl is 97 and 6 ppl are 97, it will show the gold silver and bronze for the 3 with the highest overall XP What is being overlooked here is the ordering. If numerous players have the same level there will be some ambiguity, therefore it would require ordering multiple fields maybe? I'm not gonna post any PHP but this query would give the top three without any same-level ambiguity: SELECT `username`, `level` FROM `users` ORDER BY `level` DESC, `exp` DESC LIMIT 0,3 Quote Link to comment Share on other sites More sharing options...
KyleMassacre Posted May 19, 2014 Share Posted May 19, 2014 A few errors within that bit of code, going to hit the pillow and see if I can get this sorted tomorrow Would you post the errors when you get a chance? What is being overlooked here is the ordering. If numerous players have the same level there will be some ambiguity, therefore it would require ordering multiple fields maybe? I'm not gonna post any PHP but this query would give the top three without any same-level ambiguity: SELECT `username`, `level` FROM `users` ORDER BY `level` DESC, `exp` DESC LIMIT 0,3 Good call on the experience as well 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.