我试图使用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 } }
som.. 6
foreach($result_list as $row) { $productitems[] = array( 'id' => $row['id'], 'product' => $row['product'], 'price' => $row['price'] ); }
试试这个.
foreach($result_list as $row) { $productitems[] = array( 'id' => $row['id'], 'product' => $row['product'], 'price' => $row['price'] ); }
试试这个.