Jump to content
MakeWebGames

HOF battle stats


WarMad

Recommended Posts

for my hall of fame i have battle stats on there but what i want it to do is show YOUR name and position and then show everyone elses position as normal but there names should say hidden instead of actually showing everyone elses names if i did not explain that very well let me know

Link to comment
Share on other sites

Why would you not do this at mysql level and save yourself some resources and lines of code?

MySQL runs faster than PHP, so makes logical sense to pull the data at that level.

For example :

<?php

$userid = $_SESSION['userid'];

$sql = <<<SQL
      SELECT IF(userid == $userid, username, 'Unknown') AS name 
        FROM users 
   LEFT JOIN userstats USING (userid) 
    ORDER BY (strength + agility + guard + IQ) DESC 
       LIMIT 20
SQL;

$rs = $db->query($sql);

if ($db->num_rows($rs)) {
   while ($row = $db->fetch_row($rs)) {
       echo $row['name'] . '<br />';
   }
}

 

Note I am not sure if the ORDER BY has all the right fields or if the $db class is even calling the right function names, but from memory, this looks about right;

  • Like 2
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...