Welcome Guest, Not a member yet? Register   Sign In
forum, admin rank, need help
#1

[eluser]benfike[/eluser]
Hi! I have an forum, php beast from this page. And i wanted change admin ranks...
My site have 3 rank.
rank 0= user
rank 1= only news writer (admin)
rank 2= full admin rank

and here the forum , user class file:

function is_admin($id = '')
{
$this->CI->db->where('id', $id);
$this->CI->db->select('rank');
$query = $this->CI->db->get('users');
if($query->num_rows > 0)
{
$rank = $query->row();
return $rank->rank;
}

return false;
}

and i wanted to change this, where rank=0 not admin and where rank 1 or 2 Admin.

Help me pls
#2

[eluser]Dam1an[/eluser]
I would use something like this
Code:
function is_admin($id = -1) {
    // If no ID is specified, they can't be an admin
    if($id == -1) return false;
    
    // Get the row for the user
    $this->CI->db->where('id', $id);
    $this->CI->db->select('rank');
    $query = $this->CI->db->get('users');
    if($query->num_rows > 0) {
        $user = $query->row();
        
        // They're admin if the rank is greater then 0
        return $user->rank > 0;
    } else {
        // That user ID didn't exist
        return false;
    }
}
#3

[eluser]Phil Sturgeon[/eluser]
This way is a lot cleaner.

Code:
function is_admin($id = NULL) {
    // If no ID is specified, they can't be an admin
    if($id === NULL) return FALSE;
    
    // Get the row for the user
    $this->CI->db->where('id', $id);
    $this->CI->db->where('rank >', 0);
    
    return $this->CI->db->count_all_results('users') > 0;
}
#4

[eluser]Dam1an[/eluser]
Ah yes, the good ol' count methods, why did that not occur to me?
I could use that in a fair few places to clean up my own code lol
#5

[eluser]benfike[/eluser]
Thank you
#6

[eluser]benfike[/eluser]
I have an another Question...

I have an avatar field in my users table. And on forums, when the user not upload any avatar its bugged, and don't show a default avatar. How can i use default avatar when avatar == ''?




Theme © iAndrew 2016 - Forum software by © MyBB