I have 3 columns "users", "roles" and "role_user", where the user role has 3 columns, admin(1), staff(2), and client(3) if I want to display users according to their roles how am I to go about it
You should be calling $user not $role in your foreach, since you have assigned $role to $user. Plus you will have multiple users per role. You're only returning 1 role, no need to loop through the single role, but rather the users attached to that role.