transposing table

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Christoph Lutz

    #1

    transposing table

    Hi,

    I would like to transpose a table in mysql. I have looked on the web for
    a while but nothing seems to fit the bill, so I just want to clarify if
    I have to write some php or if I can use a SQL query (preferred).
    What I would like to do is to use the values in a row as column headings
    during output, so that I can enter different sets of data into the same
    table and display it in a readable format afterwards. Let me explain: I
    have say a number of fields like so: name, email etc but I don't
    necessarily know the number of fields. I may also want to enter data
    coming from different sources into this table. I have thought about how
    I uniquely identify each "set". So, instead of creating a fixed number
    of columns, I would like the structure like this:

    ID | FieldName | FieldValue | uniqueID

    1 | name | me | 123
    2 | email | me@somwhere | 123
    3 | name | you | 456
    4 | email | you@somwhere| 456

    Afterwards, however, I would like to be able to query this table so I
    can easily show

    Name | email

    me | me@somwhere
    me | you@somwhere

    I know I can write some code to loop through and do the job but before I
    do that, I was hoping I could achieve this on the mysql end. Any
    suggestions?

    Thanks

    Christoph
Working...