How to retrieve table rows from mysql query without knowing columns names?
Now I have one known column called date
and the others are not known because it's a pivot table.
SET @sql = NULL;
SELECT
GROUP_CONCAT(DISTINCT
CONCAT(
'count(case when categoryID = ''',
categoryID,
''' then value end) AS `',
categoryID, '`'
)
) INTO @sql
FROM points;
SET @sql = CONCAT('SELECT date, ', @sql, '
FROM points
GROUP BY date');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
The result:
Php code:
<?php
$con = mysqli_connect('localhost','root','','mypointsdb');
$query= "the above query"
$exc = mysqli_query($con, $query);
$result=[];
while($row -> mysqli_fetch_array($exc)){
$result[]= $row;
}
?>
Now I want to get the table rows without column names to be like this
[2018-01-10, 0,0,0,0,1,0]
[2018-10-11, 0,0,0,0,1,0]
[2018-11-04, 1,0,1,0,1,0]
[2018-11-05, 0,0,0,1,1,3]
... etc