Jump to content

PHP Function Help!


Download

Recommended Posts

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.

 

4kqezucc.png

Notice where the username is...

wofhbmzj.png

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.