Download Posted December 20, 2010 Share Posted December 20, 2010 I created a PHP function on my website to recognize if the user is a normal, banned, pro, top player or an admin. But whenever the function goes around a username it always moves the username to the front of the loop from where it originally was. Notice where the username is... Now see where it is now? Well here is the function script.. <?php function username($username){ $staff = "SELECT * FROM users WHERE usergroup = 'Staff' AND username = '".$username."'"; if( mysql_num_rows( mysql_query( $staff ) ) == 1 ){ echo "<span class='staff'>".$username."</span>"; } $pro = "SELECT * FROM users WHERE usergroup = 'Pro' AND username = '".$username."'"; if( mysql_num_rows( mysql_query( $pro ) ) == 1 ){ echo "<span>".$username."</span>"; } $topplayer = "SELECT * FROM users ORDER BY points DESC LIMIT 1"; $result3 = mysql_query($topplayer); while($row = mysql_fetch_array($result3)){ if($username==$row['username']){ echo "<span>".$username."</span>"; } else { $else = "SELECT * FROM users WHERE banned != 'yes' AND username = '".$username."' AND usergroup != 'Staff' AND usergroup != 'Pro'"; if( mysql_num_rows( mysql_query( $else ) ) == 1 ){ echo "<span>".$username."</span>"; } } } $banned = "SELECT * FROM users WHERE banned = 'yes' AND username = '".$username."'"; if( mysql_num_rows( mysql_query( $banned ) ) == 1 ){ echo "<span>".$username."</span>"; } } ?> Any help is appreciated! Link to comment https://forums.phpfreaks.com/topic/222175-php-function-help/ Share on other sites More sharing options...
trq Posted December 20, 2010 Share Posted December 20, 2010 Besides the issue posted, why on earth are you executing 5 queries when you could be getting all the information you need in 1? Link to comment https://forums.phpfreaks.com/topic/222175-php-function-help/#findComment-1149420 Share on other sites More sharing options...
Anti-Moronic Posted December 20, 2010 Share Posted December 20, 2010 There is no need for 5 queries. $users = "SELECT * FROM users WHERE username = '".$username."'"; $userQuery = mysql_query($users); while($usersArray = mysql_fetch_assoc($userQuery)){ echo $usersArray['usergroup']; } So now you only need to compare the $usersArray['usergroup'] column: switch($usersArray['usergroup']){ case 'Staff': echo "<span>".$username."</span>"; break; case 'Pro': break; // ETC ETC } .. to check banned you just compare the $usersArray['banned'] column. No need for all of these queries. Link to comment https://forums.phpfreaks.com/topic/222175-php-function-help/#findComment-1149459 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.