title: Alias with Join in MySQL and PHP
body: <p>I'm having some issues with a many to many relationship with a simple ACL module I'm developing.</p>
  
  <p>I have three tables:</p>
  
  <p>Groups</p>
  
  <ul>
  <li>*id_group</li>
  <li>name</li>
  </ul>
  
  <p>Permissions</p>
  
  <ul>
  <li>*id_permission</li>
  <li>name</li>
  </ul>
  
  <p>RelPermissionsGroup</p>
  
  <ul>
  <li>*id_relation</li>
  <li>group</li>
  <li>permission</li>
  </ul>
  
  <p>So I had this query</p>
  
  <pre><code>SELECT * FROM acl_groups 
  LEFT OUTER JOIN acl_RelPermissionsGroup 
    ON acl_groups.id_group = acl_RelPermissionsGroup.group 
  LEFT OUTER JOIN acl_permissions 
    ON acl_permissions.id_permission = acl_RelPermissionsGroup.permission 
  WHERE id_group &gt; 0
  </code></pre>
  
  <p>If I do the query in phpmyadmin it shows fine. So, it shows all groups whether they have permissions or not and if they have it also shows them.</p>
  
  <p>I see one problem here and it is that the name attribute is repeated. How can I alias every single field?
  But that's not the problem. </p>
  
  <p>The problem is that doing mysqli_fetch_assoc performs fine except for the group that doesn't have any permissions. This is what outputs:</p>
  
  <pre><code>    Array ( 
  [id_group] =&gt; 2 
  [name] =&gt; 
  [id_relation] =&gt; 
  [group] =&gt; 
  [permission] =&gt; 
  [id_permission] =&gt; 
  )
  </code></pre>
  
  <p>The group ID is fine but given the fact that fields are duplicated it overrides them. Also, id_group and id_permission seems to be duplicated with group and permission respectively.</p>
  
  <p>What should I do?</p>