如何在不知道列名的情况下从mysql查询中检索表行?
现在我有一个称为functionOne()
的已知列,而其他列却不知道,因为它是数据透视表。
date
结果:
Php代码:
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;
现在我要使没有列名称的表行变成这样
<?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;
}
?>
答案 0 :(得分:0)
要仅以简单数组形式获取数据,可以使用mysqli_fetch_row()
代替mysqli_fetch_array()
。
所以您的代码可能是这样的:
<?php
$con = mysqli_connect('localhost','root','','mypointsdb');
$query= "the above query"
$exc = mysqli_query($con, $query);
$result=[];
while($row = mysqli_fetch_row($exc)){
$result[]= $row;
}
?>