foreach 루프를 사용하여 테이블을 채울 값을 설정하려고합니다. 어떤 이유로 인해 배열에 null 값이 표시됩니다. 하지만 내가 var에 $ result_list []를 덤프하면 제품 배열이 표시됩니다. 내가 잘못 했나요? 덕분에Mysql 가져 오기 배열 Foreach
$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 } }
이 아니 $ 로우 -> 아이디하지만 $ 행 [ 'ID'] – GGio
마 더 이상 사용되지 않는'mysql_ * '함수를 사용하지 마라. – Voitcus
더 이상 사용되지 않는 것은 무엇입니까? – Brent