我编写了mysql查询来动态地将行转换为列。当我向prn发送静态值时,此查询正常工作。但是当我从$ prn获取输入时,我将作为空数组出来。 以下是代码 -
$prn=$_GET['prn'];
echo 'prn:'.$prn;
$sql = "SET @sql = NULL;
SELECT
GROUP_CONCAT(DISTINCT
CONCAT(
'GROUP_CONCAT(IF(finding_field = ''',
finding_field,
''',finding_value, NULL)) AS ',
finding_field
)
) INTO @sql
FROM cpc_specific_finding;
SET @sql = CONCAT('SELECT finding_no
, ', @sql, '
FROM cpc_specific_finding
where prn='$prn'
GROUP BY finding_no');
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;";
$mydata = array();
if (mysqli_multi_query($localCon,$sql)){
do{
if ($result= mysqli_store_result($localCon)) {
while ($row=mysqli_fetch_assoc($result)){
$mydata[] = $row;
}
mysqli_free_result($result);
}
}
while (mysqli_next_result($localCon));
}
echo json_encode($mydata);
我尝试过编写prn ='"。$ prn。"'哪个不起作用。
答案 0 :(得分:0)
我得到了答案:D。如果有人发现有帮助,我会发帖回答。
在prn的第三个查询值中传递了''如此删除的引号,它应该是。
export class LanguageActions implements OnInit {
lang: string;
private sub: any;
constructor(private _route: ActivatedRoute) {
}
ngOnInit() {
this.sub = this._route.params.subscribe(params => {
this.lang= params['lang'];
});
}
}
并且有效。