Jump to content
MakeWebGames

Crown Images Help


Reecey12345

Recommended Posts

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.

Link to comment
Share on other sites

$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 by Samurai Legend
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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++;
}
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.   Paste as plain text instead

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