title: Roles and permissions in php
body: <p>I am making a menu, but I want to limit it to only some users with a specific permission can see it.</p>
  
  <p>the query:</p>
  
  <blockquote>
    <p><strong>SELECT idpermission,userid FROM user_permissions WHERE userid = "U001"</strong></p>
  </blockquote>
  
  <p>Result: User U001 has 3 permissions stored.</p>
  
  <blockquote>
  <pre><code>idpermission,userid
   IDP001,U001
   IDP002,U001
   IDP003,U001
  </code></pre>
  </blockquote>
  
  <p>I have 3 tables <strong>(users,permissions and user_permissions)</strong>, in <strong>user_permissions</strong> I store each permission of each user</p>
  
  <pre><code>Example:
  
  Table
  
  user | permission | user_permissions
  
  result:
  
  user: u001,carlos,carlos@...
  
  permissions: IDP001 = book | IDP002 = create_book | IDP003 = edit_book | IDP004 = user | IDP005 = edit_user...
  
  user_permissions:
  IDP001,U001
  IDP002,U001
  IDP003,U001
  IDP001,U002
  IDP003,U002...
  </code></pre>
  
  <p>when i call the query</p>
  
  <blockquote>
  <pre><code>while($sqlRow=$sqlPermissions-&gt;fetch(PDO::FETCH_ASSOC))
   {
     if ($sqlRow['idpermission'] == 'IDP001' || $sqlRow['idpermission'] == 'IDP002' || $sqlRow['idpermission'] == 'IDP003')
       {
          echo "user menu ";
       }
   }
  </code></pre>
  </blockquote>
  
  <p>but the result that appears to me is 3:</p>
  
  <blockquote>
    <p><strong>user menu user menu user menu</strong></p>
  </blockquote>
  
  <p>You should only show me one, making only a comparison if you have such permission shows but shows nothing.</p>
  
  <p>What I want to reach is that the user can have many permissions for different items on the menu, such as view, edit, create, delete, each one is a permission, and each item (user menu, books menu) is another permission.</p>