0

Well i'm new at writing this code how to create ranks for users. well i actully don't even know how to start with this and i already searched more than 20 websites about how to create ranks

I want to have something like that

Ranks:

1 = normal user

2 = power user

3 = uploader

4 = VIP

5 = Moderator

6 = Administrator

7 = SysOP**

4
  • 2
    Is the question how to store that data or how to have those roles function on your site? Commented Dec 20, 2015 at 20:25
  • @chris85 how to have thos roles function on my site Commented Dec 20, 2015 at 20:46
  • Instead of searching for ranks, search for authorization. SO has many questions with great answers like one with java script or using the header. COuld you please elaborate more, at this point your question is a little vague Commented Dec 20, 2015 at 23:37
  • @davejal okey i will search for authorization. Well i have something like that in my mind.... If you are power user you can make request for uploader rank so you can upload files but if you are uploader you can post files ( you have acces to upload.php witch normal , powerusers cant reach upload.php ) Commented Dec 21, 2015 at 12:30

1 Answer 1

0

Well you'll have at least two tables. One for ranks and another for users. You can implement it like so:

Create the tables

<?php
    $link=mysqli_connect("host","user","pass","db");
    $sql="CREATE TABLE ranks (id INT(6), name VARCHAR(30))";
    $link->query($sql);
    $sql="CREATE TABLE users (id INT(6) AUTO_INCREMENT PRIMARY KEY, rank INT(6), name VARCHAR(64))";
    $link->query($sql);
?>

Insert some ranks and users...

<?php
    $sql="INSERT INTO ranks (id, name) VALUES(1, \"normal user\")";
    $link->query($sql);
    $sql="INSERT INTO ranks (id, name) VALUES(2, \"power user\")";
    $link->query($sql);
    $sql="INSERT INTO ranks (id, name) VALUES(3, \"uploader\")";
    $link->query($sql);
    //...
    $sql="INSERT INTO users (rank, name) VALUES(1, \"Harry Potter\")";
    $link->query($sql);
    $sql="INSERT INTO users (rank, name) VALUES(3, \"Hermoine Granger\")";
    $link->query($sql);
?>

You can view your users like so:

<?php
    $sql="SELECT * FROM users";
    $res=$link->query($sql);
    while($row=mysqli_fetch_assoc($res)){
        echo "User:".$row['name']." Rank:".$row['rank']."<br>";
    }
?>
Sign up to request clarification or add additional context in comments.

2 Comments

I have datebase name dbtest and table name users and it's look like this so gyazo.com/3eabd76d189f803016666a02b3313e31 (image here)
It looks like you have a pre-existing table there with strange fields in it. You might want to start with a clean database. Create a new db and use that.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.