Jump to content

Members' Status Levels


Goldeneye

Recommended Posts

Greetings:

 

I'm working on this kind of CMS, and have 5 user levels..

-1: Banned; 1: New User; 2: Regular User; 3: Moderator; and 4: Administrator.

 

So in the user profiles I'm trying to get #: (Level Title).. so like 4: (Administrator).

Here's what I did to do that

<?php
else if($user !== $_SESSION['user_id']){
	$query = mysql_query("SELECT id, username, email, level FROM userbase") or die(mysql_error());
	while ($row = mysql_fetch_array($query)){
		if($_GET['user'] == $row['id']){
			gHeader('Userlist: '.$row['username']);
			echo '<table border="1px">';
			echo '<tr><td>username</td><td>' . $row['username'] . '</td><tr>';
			echo '<tr><td>User ID</td><td>' . $row['id'] . '</td><tr>';
			echo '<tr><td>Email</td><td>' . $row['email'] . '</td><tr>';
			echo '<tr><td>User Level</td><td>' . $row['level']; levelTitles() . '</td><tr>';
			echo '</table>';
		}
	}
}
?>

 

Here's the levelTitles() function:

<?php
function levelTitles(){
if($row['level'] = '4') {echo ' (Administrator)';}
else if($row['level'] = '3') {echo ' (Moderator)';}
else if($row['level'] = '2') {echo ' (Regular User)';}
else if($row['level'] = '1') {echo ' (New User)';}
else if($row['level'] = -'1') {echo ' (Banned)';}

?>

 

That seemed to worked fine if you're an Administrator because it'll display "4 (Administrator)." So I tried that out on my test account which is a New User, and it displayed, "1 (Administrator)."

 

I'm sure this whole thing is actually very easy, and I'm just completely overlooking it, but any help would be greatly appreciated..

Link to comment
https://forums.phpfreaks.com/topic/97380-members-status-levels/
Share on other sites

the function levelTitles() does not have access to $row, plus you're assigning a value to it instead of comparing, so $row['level'] = '4' will always be true in the function levelTitles()

 

i suggest that you pass $row['level'] as a parameter:

 

function levelTitles($level){
if($level == '4') {
            echo ' (Administrator)';
        } else if($level == '3') {
            echo ' (Moderator)';
        } else if($level == '2') {
            echo ' (Regular User)';
        } else if($level == '1') {
            echo ' (New User)';
        } else if($level == -'1') {
            echo ' (Banned)';
        }
}

// Called using
echo '<tr><td>User Level</td><td>' . $row['level']; levelTitles($row['level']) . '</td><tr>';

Link to comment
https://forums.phpfreaks.com/topic/97380-members-status-levels/#findComment-498290
Share on other sites

<?php
else if($user !== $_SESSION['user_id']){
	$query = mysql_query("SELECT id, username, email, level FROM userbase") or die(mysql_error());
	while ($row = mysql_fetch_array($query)){
		if($_GET['user'] == $row['id']){
			gHeader('Userlist: '.$row['username']);
			echo '<table border="1px">';
			echo '<tr><td>username</td><td>' . $row['username'] . '</td><tr>';
			echo '<tr><td>User ID</td><td>' . $row['id'] . '</td><tr>';
			echo '<tr><td>Email</td><td>' . $row['email'] . '</td><tr>';
			echo '<tr><td>User Level</td><td>' . $row['level']; levelTitles($row['level']) . '</td><tr>';
			echo '</table>';
		}
	}
}
?>

 

<?php
function levelTitles($titleno){
if($titleno == '4') {echo ' (Administrator)';}
else if($titleno == '3') {echo ' (Moderator)';}
else if($titleno == '2') {echo ' (Regular User)';}
else if($titleno == '1') {echo ' (New User)';}
else if($titleno == -'1') {echo ' (Banned)';}

?>

 

I'm don't have access to a server so I can't test it ATM.

 

EDIT: Didn't notice the single = instead of comparator.

Link to comment
https://forums.phpfreaks.com/topic/97380-members-status-levels/#findComment-498291
Share on other sites

So I have to do a separate query for the levelTitles() function? Alright, that's understandable. I thought because the query was already present in the IF statement, then I could just use that as long as the levelTitles() function came after that.

Also, I tried using the comparison operator, and it didn't even return anything.. But the Separate query would change that?

 

Of course, it makes sense now. I tried something like that in the first place but instead used an array for the user levels instead of IF statements.

 

I also did try doing a comparison instead of an assignment, but it didn't even return anything. So I just switched back to assignments.

 

I give your code a shot, thanks a lot guys.

Link to comment
https://forums.phpfreaks.com/topic/97380-members-status-levels/#findComment-498297
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.