Mysql Fetch Array Foreach

Bre*_*ent 1 php mysql arrays

我试图使用foreach循环来设置值来填充表,由于某种原因我的数组在值内显示null.但是当我转储$ result_list []时它会显示产品数组,我这样做错了吗?谢谢

$result = mysql_query("SELECT id, product, price FROM products");


$result_list = array();
while($row = mysql_fetch_array($result)) {
   $result_list[] = $row;
}

foreach($result_list as $row) {

    $productitems[] = array(
        'id' => $row->id,
        'product'  => $row->product,
        'price'  => $row->price
    );              
}

var_dump($productitems);


array(2) { [0]=> array(3) { ["id"]=> NULL ["product"]=> NULL ["price"]=> NULL } [1]=> array(3) { ["id"]=> NULL ["product"]=> NULL ["price"]=> NULL } } 
Run Code Online (Sandbox Code Playgroud)

som*_*som 6

foreach($result_list as $row) {

    $productitems[] = array(
        'id' => $row['id'],
        'product'  => $row['product'],
        'price'  => $row['price']
    );              
}
Run Code Online (Sandbox Code Playgroud)

试试这个.