I am currently having an issue where I have an enum named 'Privilege' where 0 = normal and 1 = privileged. These are assigned to jobs e.g. worker has normal privilege but CEO has admin privileges. An issue I have run into is where a user might have two jobs, where one is normal privileged and the other is admin privileged. I have written a query, in order to start sessions depending on the privilege,however when I use group by StaffID, I'm unsure on how to group by the highest privilege (1 being the case).
E.g.
else if ($pwdCheck == True){
session_start();
$query = mysqli_query($conn, 'SELECT staff.StaffID, role.Privilege FROM jobs
INNER JOIN staff ON staff.StaffID = jobs.StaffID
INNER JOIN role ON role.RoleID = jobs.RoleID GROUP BY StaffID
');
$gettier = mysqli_fetch_assoc($query);
if($gettier["Privilege"] === 'normal'){
$_SESSION['userID'] = $row['LoginID'];
header("Location: staffindex.php?login=USERsuccess");
}
elseif($gettier["Privilege"] === 'privileged'){
$_SESSION['AdminID'] = $row['LoginID'];
header("Location: staffindex.php?login=ADMINsuccess");
}
exit();
}
This is where in all cases, wen I enter a privileged person, I am still redirected with the USERsuccess header. I assume I will need to use an aggregate string function (after some research) but I don't really understand how to apply it.
Please view the image to see query in action:
With Group By: https://i.stack.imgur.com/XIZ8L.jpg
Without Group By: https://i.stack.imgur.com/gOJxx.jpg
Any help is appreciated.