'php code to execute mysql pivot table statement
below is mysql code that creates for me a pivot table in mysql. i have tried to run it in php but it doesn't work. how can i execute the code in php so that i can load it in an array to generate reports
SET @sql = NULL; SELECT GROUP_CONCAT(DISTINCT CONCAT( 'max(IF(unit_name = ''', unit_name, ''', cat+exam, NULL)) AS', CONCAT("'", unit_name, "'") ) ) INTO @sql FROM temp_results; SET @sql = CONCAT('SELECT adm, name, ', @sql, ' FROM temp_results where course_code="1601/1" GROUP BY adm'); PREPARE stmt FROM @sql; EXECUTE stmt;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|