我正在尝试使用 foreach 循环来设置值以填充表,由于某种原因,我的数组在值内显示为空。但是当我 var dump $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 } }