Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

183
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda