Goldeneye Posted March 22, 2008 Share Posted March 22, 2008 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 More sharing options...
BlueSkyIS Posted March 22, 2008 Share Posted March 22, 2008 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 More sharing options...
metrostars Posted March 22, 2008 Share Posted March 22, 2008 <?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 More sharing options...
BlueSkyIS Posted March 22, 2008 Share Posted March 22, 2008 ^ No. You're still assigning with one = instead of comparing with two ==. $titleno = '4' will always be true and you'll still always see (Administrator). Link to comment https://forums.phpfreaks.com/topic/97380-members-status-levels/#findComment-498292 Share on other sites More sharing options...
Goldeneye Posted March 22, 2008 Author Share Posted March 22, 2008 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 More sharing options...
jkewlo Posted March 22, 2008 Share Posted March 22, 2008 how did it work out for you? Link to comment https://forums.phpfreaks.com/topic/97380-members-status-levels/#findComment-498299 Share on other sites More sharing options...
Goldeneye Posted March 22, 2008 Author Share Posted March 22, 2008 metrostars' code gave me a warning Warning: Missing argument 1 for leveltitles() in /home/gen/sites/globals.php on line 28 Link to comment https://forums.phpfreaks.com/topic/97380-members-status-levels/#findComment-498303 Share on other sites More sharing options...
metrostars Posted March 22, 2008 Share Posted March 22, 2008 Did you change the 1st piece of code as well as the 2nd? Link to comment https://forums.phpfreaks.com/topic/97380-members-status-levels/#findComment-498310 Share on other sites More sharing options...
Goldeneye Posted March 22, 2008 Author Share Posted March 22, 2008 Nevemind, I got it, there was an IF statement before the one I put up here in that script so I had to change that as well. Thanks a lot! Link to comment https://forums.phpfreaks.com/topic/97380-members-status-levels/#findComment-498313 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.