0
 $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
4

1 回答 1

0

你不需要 2 个数组。您可以(并且应该)将 id 存储为结果数组的键。

while($row = mysqli_fetch_array($result))
{
    $goal[$row['metric_id']] = $row['metric_desc']);
}

或者,在SafeMysql 库的帮助下,整个代码可以更改为

$goal = $db->getIndCol('metric_id',"SELECT * FROM metrics where ini_name = ?i",$ini);
于 2013-03-28T18:13:39.923 回答