Php Sqli数组问题
我试图将数据库中的值推送到数组中,但收到一条警告Php Sqli数组问题,php,mysql,mysqli,Php,Mysql,Mysqli,我试图将数据库中的值推送到数组中,但收到一条警告 $goal=array(); //goal $sql=""; //!mysqli_query($con,$sql)) $result = mysqli_query($con,"SELECT * FROM metrics where ini_name = '$ini'");/*table name*/
$goal=array();
//goal
$sql="";
//!mysqli_query($con,$sql))
$result = mysqli_query($con,"SELECT * FROM metrics where ini_name = '$ini'");/*table name*/
while($row = mysqli_fetch_array($result))
{
array_push($goal,$row['metric_desc']);/*column name*/
array_push($goal_id,$row['metric_id']);
}
$matrix=array();
//goal
$sql="";
您不需要2个数组。您可以(也应该)将id存储为结果数组的键
Warning: array_push() expects parameter 1 to be array, null given in C:\xampp\htdocs\xampp\Testing\Int\sq2.php on line 195
或者,借助于,整体您的代码可以更改为
while($row = mysqli_fetch_array($result))
{
$goal[$row['metric_id']] = $row['metric_desc']);
}
什么是
$goal\u id
?您尚未在发布的代码中将其定义为数组。请尝试将目标和目标id初始化为数组…类似于$goal=array()代码>@YueYuan谢谢你解决了这个问题problem@MichaelBerkowski谢谢你,迈克尔
$goal = $db->getIndCol('metric_id',"SELECT * FROM metrics where ini_name = ?i",$ini);