User Rank On Profile


This is a pretty simple tutorial just got to add one or two lines of code and a new mySQL Table :P

First run this through PHPMyAdmin:
PHP Code
  1. CREATE TABLE `groups` (
  2. `id` int(11) NOT NULL auto_increment,
  3. `lvlnum` int(3) NOT NULL default '1',
  4. `full_name` varchar(255) NOT NULL,
  5. PRIMARY KEY (`id`)
  6. ) ENGINE=MyISAM;
  7. INSERT INTO `groups` (`lvlnum`,`full_name`) VALUES ('1','Unverified Member');
  8. INSERT INTO `groups` (`lvlnum`,`full_name`) VALUES ('2','Member');
  9. INSERT INTO `groups` (`lvlnum`,`full_name`) VALUES ('4','Moderator');
  10. INSERT INTO `groups` (`lvlnum`,`full_name`) VALUES ('6','Administrator');


Alright. On your members.php find:
PHP Code
  1. $user = mysql_fetch_array($getuser);


Add After:
PHP Code
  1. $user_rank = mysql_fetch_array(mysql_query("SELECT * FROM `groups` WHERE `lvlnum` = '$user[userlevel]';"));


Now Find:
PHP Code
  1. Email: $user[email]<br>


Add After:
PHP Code
  1. User Rank: $user_rank[full_name]<br>


That should be it. :P
ShadowMage's Avatar
Author:
Views:
3,908
Rating:
Posted on Thursday 14th August 2008 at 12:55 AM
UrbanTwitch
UrbanTwitch's Avatar
PHP Code
  1. if ($user[userlevel] == 6) {
  2.  
  3. echo "Rank: Administrator";
  4. }elseif ($user[userlevel] == 4) {
  5.  
  6. echo "Rank: Moderator";
  7. }elseif ($user[userlevel] == 2) {
  8.  
  9. echo "Rank: Moderator";
  10. }


Thats the only way I see it jambomb.
Posted on Wednesday 13th August 2008 at 10:00 PM
jambomb
jambomb's Avatar
how do i make it so it doesnt HAVE To be on members page.. ? coz it only works on members page
Posted on Wednesday 16th July 2008 at 11:39 AM
Dava
Dava's Avatar
UrbanTwitch check your edits because i have this working same with every tutorial on this site apart from member pagination which im tryin to sort out
Posted on Tuesday 15th July 2008 at 07:44 PM
UrbanTwitch
UrbanTwitch's Avatar
Does anyone else get this: Fatal error: Call to undefined function change_levels() in /home/jsfdan/public_html/members.php on line 33?
Posted on Tuesday 15th July 2008 at 06:01 PM
UrbanTwitch
UrbanTwitch's Avatar
This doesn't work. :
Posted on Wednesday 11th June 2008 at 09:24 PM
SkillMaster
SkillMaster's Avatar
Ah but in online.php you have included config.php what you need to do. is create a functions.php file and put all the function coding in there AND only include functions.php in the pages that you need.
Posted on Monday 9th June 2008 at 04:27 AM
Adam981
Adam981's Avatar
haha! i fixed it, just place

PHP Code
  1. <?php
  2. function change_levels($level){ //define the function
  3. $listed = array('2','4','6'); // define your levels
  4. // if you wish to add to this list just add '', between the quotes add the rank number.
  5. $changed = array('Member','Moderator','Admin'); //this is the changed rank name
  6. //Again if you wish to add to the like just add '',
  7. return str_replace($listed, $changed, $level); //replace the listed rank with the rank name
  8. } //End the function
  9. ?>


under where u would put

Code
$user_rank = change_levels($user[userlevel]); //change level
Posted on Sunday 8th June 2008 at 11:14 PM
Adam981
Adam981's Avatar
Fatal error: Cannot redeclare change_levels() (previously declared in /home/crystal/public_html/config.php:26) in /home/crystal/public_html/config.php on line 32


include online.php doesnt have config..
PHP Code
  1. <?
  2. session_start(); //allows session
  3. include ('online.php');
  4. $conn = mysql_connect("localhost","xxx","xxx");
  5. mysql_select_db(xxx) or die(mysql_error());
  6.  
  7. $logged = MYSQL_QUERY("SELECT * FROM `members` WHERE `id` = '$_SESSION[id]' AND `password` = '$_SESSION[password]'");
  8. $logged = mysql_fetch_array($logged);
  9.  
  10. //some server details, don't edit!
  11. $host = $_SERVER['HTTP_HOST'];
  12. $self = $_SERVER['PHP_SELF'];
  13.  
  14. //change this to your site name
  15. $sitename = "My Site";
  16.  
  17. //Send emails or not (email activation). 1 = true, 0 = false
  18. $semail = "0";
  19.  
  20.  
  21. $sets = mysql_query("SELECT * FROM site_stats WHERE `sid` = '1';");
  22. $setting = mysql_fetch_array($sets);
  23. //get the info and let it be used all over the site :)
  24.  
  25.  
  26. function change_levels($level){ //define the function
  27. $listed = array('2','4','6'); // define your levels
  28. // if you wish to add to this list just add '', between the quotes add the rank number.
  29. $changed = array('Member','Moderator','Admin'); //this is the changed rank name
  30. //Again if you wish to add to the like just add '',
  31. return str_replace($listed, $changed, $level); //replace the listed rank with the rank name
  32. } //End the function
  33.  
  34.  
  35.  
  36.  
  37. ?>
Posted on Friday 6th June 2008 at 06:48 AM
SkillMaster
SkillMaster's Avatar
You are obviously using include();, therefore you have included config.php twice. Remove it from the top of this script.
Posted on Friday 6th June 2008 at 06:15 AM
zerocool
zerocool's Avatar
i have the same error as Adam981