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

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Hartman
  • 105
  • 1
  • 9
  • 2
    Is the question how to store that data or how to have those roles function on your site? – chris85 Dec 20 '15 at 20:25
  • @chris85 how to have thos roles function on my site – Hartman Dec 20 '15 at 20:46
  • Instead of searching for ranks, search for authorization. SO has many questions with great answers like [one with java script](http://stackoverflow.com/q/8896835/3664960) or [using the header](http://stackoverflow.com/q/30599506/3664960). COuld you please elaborate more, at this point your question is a little vague – davejal Dec 20 '15 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 ) – Hartman Dec 21 '15 at 12:30

1 Answers1

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>";
    }
?>
cantelope
  • 1,147
  • 7
  • 9
  • I have datebase name dbtest and table name users and it's look like this so https://gyazo.com/3eabd76d189f803016666a02b3313e31 (image here) – Hartman Dec 20 '15 at 20:59
  • 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. – cantelope Dec 20 '15 at 21:02