$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="";
我正在尝试将数据库中的值推送到数组中,但是我收到了警告
Warning: array_push() expects parameter 1 to be array, null given in C:\xampp\htdocs\xampp\Testing\Int\sq2.php on line 195
答案 0 :(得分:0)
你不需要2个阵列。您可以(并且应该)将id存储为结果数组的键。
while($row = mysqli_fetch_array($result))
{
$goal[$row['metric_id']] = $row['metric_desc']);
}
或者,在SafeMysql library的帮助下,整个,您的代码可以更改为
$goal = $db->getIndCol('metric_id',"SELECT * FROM metrics where ini_name = ?i",$ini);