Skip to content Skip to sidebar Skip to footer

Display Rows From MYSQL Query As Columns In HTML Table

I have a MYSQL database storing levels for students for each terms work. I'm fine creating the php page, with query etc and very comfortable with the hmtl/css required to create ta

Solution 1:

You need to pivot your results. Unfortunately MySQL does have PIVOT but you can build a query like this to achieve the same results

SELECT student_id, 
  MAX(CASE WHEN term = 'aut7' THEN level END) Aut7,
  MAX(CASE WHEN term = 'spr7' THEN level END) Spr7,
  MAX(CASE WHEN term = 'sum7' THEN level END) Sum7
FROM student_terms
GROUP BY student_id

See demo in SQL Fiddle


Post a Comment for "Display Rows From MYSQL Query As Columns In HTML Table"