title: Codeigniter admin and user role
body: <p>I'm making a login system with 2 roles one for 'admin' and one for 'user'. I tried to make a else if statement for the login. This for the user login actually what happens now that every user is going to the admin_view right now. </p>
  
  <p>In my database the row is called 'admin' which is a boolean so if the column 'admin' is 1 in the users table. The admin_view should be loaded if the value is 0 the user_view needs to be loaded. </p>
  
  <p>I really don't know what to do now.</p>
  
  <p>How do I need to seperate the roles between the admin and user?</p>
  
  <p>Here is my controller: users.php</p>
  
  <pre><code>public function login() {
      $this-&gt;form_validation-&gt;set_rules('username', 'Username', 'trim|required|min_length[3]');
      $this-&gt;form_validation-&gt;set_rules('password', 'Password', 'trim|required|min_length[3]');
      $this-&gt;form_validation-&gt;set_rules('confirm_password', 'Confirm Password', 'trim|required|min_length[3]|matches[password]');
  
      if ($this-&gt;form_validation-&gt;run() == FALSE) {
          $data = array(
              'errors' =&gt; validation_errors()
              );
  
          $this-&gt;session-&gt;set_flashdata($data);
  
          redirect('home');
      } else {
          $username = $this-&gt;input-&gt;post('username');
          $password = $this-&gt;input-&gt;post('password');
          $user_id = $this-&gt;user_model-&gt;login_user($username, $password);
  
          if($user_id) {
              $user_data = array(
                  'user_id'   =&gt; $user_id,
                  'username'  =&gt; $username,
                  'logged_in' =&gt; true
                  'admin' =&gt; 1;
                  );
  
              $this-&gt;session-&gt;set_userdata($user_data);
              $this-&gt;session-&gt;set_flashdata('login_success', 'You are now logged in');
              $data['main_view'] = "admin_view";
              $this-&gt;load-&gt;view('layouts/main', $data);
  
          } 
          // Here I want the user_view to load op if the user haa a 0 value in 
  in the column admin.
          else if($user_id) {
              $user_data = array(
                  'user_id'   =&gt; $user_id,
                  'username'  =&gt; $username,
                  'logged_in' =&gt; true,
                  'admin'     =&gt; 0;
                  );
  
              $this-&gt;session-&gt;set_userdata($user_data);
              $this-&gt;session-&gt;set_flashdata('login_success', 'You are now logged in');
              $data['main_view'] = "user_view";
              $this-&gt;load-&gt;view('layouts/main', $data);
  
          } else {
              $this-&gt;session-&gt;set_flashdata('login_failed', 'Sorry, you are not logged in');
              redirect('home/index');
          }
      }
  }
  </code></pre>
  
  <p>Here is my model: user_model.php</p>
  
  <pre><code>public function login_user($username, $password) {
      $this-&gt;db-&gt;where('username', $username);
      $result = $this-&gt;db-&gt;get('users');
      $db_password = $result-&gt;row(2)-&gt;password;
      $admin = $result-&gt;row(7)-&gt;admin;
  
      if(password_verify($password, $db_password)) {
          return $result-&gt;row(0)-&gt;id;
      } else {
          return false;
      }
  
  }
  }
  </code></pre>
  
  <p>I apperciate the help.</p>