Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
Various roles for one user in PHP

I have an idea of doing a back office for my website. The problem is that, when I introduce a user who has, for example, two roles, I want the user to choose the role to work with, but I can't figure out how to do that. I've tried so different things such as putting the two roles separate with commas in MySQL and separating them in PHP but it didn't work.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

let say you have a user table, and a user can have multiple role.

you can create a master table for role ( let say roles )

role table

you can have a field on user table say user_roles -> it can have values like 1,2,4

note:- there should not be gaps between the numbers / comma

on the front-end you can take a mutiselect / tags UI element to input role for the user.

to fetch the role of a user at server side - you can use explode() + in_array() to check the role if exists

comma separated example

EDIT:-

It requires validation when adding roles ( ie: which user's role is allowed to select when already selected specific types ) For authorization, the user's roles should be added to the session :- this will help when allowing the user to do tasks he is allowed to do.

you can take a third table to maintain user's roles ( as suggested by @ADyson ), this will help if you want to join tables based on user + roles but you will need to join roles table for getting user data when starting session for the user.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!