title: Joomla: get the user group from the page access level using PHP
body: <p>In Joomla 2.5.16:</p>
  
  <ol>
  <li>Suppose user 100 belongs to user groups 14 and 16.</li>
  <li>Suppose that the page he's currently viewing has an access level id of 6.</li>
  <li>According to the table 'viewlevels' in the MySQL database, access level 6 is available for groups 8, 16 and 17</li>
  </ol>
  
  <p>My goal is to find the "right" user group for this page. Since the user belongs to 2 user groups and one of them (16) is contained in the array of groups allowed to see this page, how can I query the database to find that group?</p>
  
  <p>I tried:</p>
  
  <pre><code>$usr_id=100;
  $access=6;
  
  $query(SELECT rules from 'viewlevels' WHERE ???);
  </code></pre>
  
  <p>Table viewlevels has a structure like:</p>
  
  <pre><code>ID   | rules
  6   |[8,16,17]
  </code></pre>
  
  <p>Table user_usergroup_map has a structure like:</p>
  
  <pre><code>User_id   |Group_id
  100   |14
  100   |16
  </code></pre>
  
  <p>Any help, please?</p>