title: Select MySQL row value as column title?
body: <p>I'm trying to do a customizable and extendable profile system for my CMS. From the user perspective it is straight forward, but for the admin I want all data, including the profile data, to be searchable. Profile fields may be added by "plugins", which may also add new fields to search on. I don't know if what I'm trying to do with MySQL to make this work is possible or if I'm going at it completely the wrong way.</p>
  
  <p>So I have the users stored in one table (users), with columns for id, email, password and access_level.</p>
  
  <p>I then have another table with profile information (profiles), stored as user_id, parameter and value. The parameter could eventually be put into a separate table again (so it isn't repeating itself), but for now I'll leave it like this.</p>
  
  <p>The parameter and value are basically the profile data. For example, parameter may be "age" and the value may be "22".</p>
  
  <p>What I want to try and do, is select the users table, with the profile information joined so the parameter is mapped to an additional column. So it ends up like so, straight from MySQL:</p>
  
  <pre><code>id    email    password    access_level   age
  1     a@a.com  *****       1              22
  2     b@b.com  *****       2              25
  3     c@c.com  *****       2              25
  </code></pre>
  
  <p>I've been looking at pivot tables all afternoon, but from all I can see the "column name" is pre-defined. In this case I want the "column name" to come from the row itself.</p>
  
  <p>If it isn't possible to do it with a single query, what other methods are there? I'm using PHP if the best method is to do it via that.</p>
  
  <p>Any suggestions would be much appreciated. :)</p>