I changed the query to SELECT users.id FROM users JOIN roles ON roles.id = users.user_level WHERE roles.role_status = '{$db->escape($role_status)}' , I am trying to get the users whose user_level = role_id which its status = '0' or '1', I checked this SQL query with phpmyadmin and it is working fine, and actually I don't know what to do after that :( , I mean I don't know what to write with $current_user['role_status'] instead of role_status to get what I want.
PHP function error Notice: Undefined index:
Shortly I need to block a group of users at once according to their role status (banned or not) instead of blocking users one by one. I tried using fk on update cascade to control the role status by making a fk user_role_status column in the users table refers to role_status column in the roles table but without luck because when I change a role status in roles table it changes the whole user_role_status column in users table not only the role I changed then it blocks all users not only the group I want to block because role_status in roles table is not unique and I can't make it unique because its all cells contain value='1', so I deleted the column and gave up that idea
// role_status in roles table is a fk refers to id in statuses table.
statuses_table
id is_active
------------------
0 no
1 ok
roles_table
id role role_status
--------------------------------------
1 Admins 1
2 Editors 1
3 Users 1
users_table
id user_name user_level
---------------------------------------
1 Admin 1
2 Editor1 2
3 User1 3
4 Editor2 2
5 User2 3
6 User3 3
and this is the function I use
--------------------------------------------------------------
Find role status
--------------------------------------------------------------
function find_by_current_rolStatus($role_status)
{
global $db;
$sql = "SELECT users.id FROM users JOIN roles ON roles.id = users.user_level WHERE roles.role_status = '{$db->escape($role_status)}'";
$result = $db->query($sql);
return($db->num_rows($result) === 0 ? true : false);
}
--------------------------------------------------------------
Function for checking if user role status banned or allowed
--------------------------------------------------------------
function login_require_roleStatus($require_role_status)
{
global $session;
$current_user = current_user();
$current_user_role_status = find_by_current_rolStatus($current_user['role_status']);//line 155
//if Role status Deactive
if ($current_user['role_status'] === '0')://line 157
$session->msg('Banned');
redirect('home.php',false);
//if user role allowed
elseif($current_user['role_status'] === '1')://line 161
return true;
endif;
}
and I got this error
Notice: Undefined index: role_status in sql.php on line 155
Notice: Undefined index: role_status in sql.php on line 157
Notice: Undefined index: role_status in sql.php on line 161
Please or to participate in this conversation.