How to convert mysql pivot table to HTML table

Hi I’ve got the following pivot table from mysql database: enter image description here

I obtain it using the following stored procedure:

BEGIN
    SELECT

    GROUP_CONCAT(
    CONCAT("MAX(IF(km_kondomanager_millesimal_table_value_table_id='", km_kondomanager_millesimal_table_value_table_id, "',km_kondomanager_millesimal_table_millesimal_value ,NULL)) AS '", km_kondomanager_millesimal_table_name, "'"), "
"
      )INTO @answers
    FROM (
      SELECT DISTINCT km_kondomanager_millesimal_table_value_table_id, km_kondomanager_millesimal_table_name FROM km_kondomanager_millesimal_table_values INNER JOIN km_kondomanager_millesimal_table
                 ON km_kondomanager_millesimal_table_values . km_kondomanager_millesimal_table_value_table_id = km_kondomanager_millesimal_table. km_kondomanager_millesimal_table_id WHERE km_kondomanager_millesimal_table_value_group_id = km_group
    ) A;

    SET @query := 
      CONCAT(
        'SELECT km_kondomanager_millesimal_table_value_building_id, ', @answers, 
        ' FROM km_kondomanager_millesimal_table_values WHERE km_kondomanager_millesimal_table_value_group_id = ',km_group,' GROUP BY km_kondomanager_millesimal_table_value_building_id'
      );

    PREPARE statement FROM @query;
    EXECUTE statement;
END

Where “km_group” is a IN parameter, the question is how can I call this stored procedure from PHP and build a HTML table that look exactly the same as the pivot I’ve got on the picture? Many thanks

Check this out.

FYI: Your super long column names makes for difficult reading.