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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

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

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

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.