但执行以下代码时收到 2 个错误:
消息:未定义索引:rt_default_price 文件名:controllers/reservations.php 行号:24
消息:非法偏移类型文件名:controllers/reservations.php 行号:24
第 24 行是...
$combined[] = array($key => $arrVals[$i]);
控制器(reservations.php)
$arrVals['rt_name'] = $this->reservations_model->pop_room_type(); /* This is the 1st Array:
Array
(
[rt_name] => Array
(
[0] => Array
(
[rt_name] => Business
)
[1] => Array
(
[rt_name] => Econ
)
[2] => Array
(
[rt_name] => Luxury
)
[3] => Array
(
[rt_name] => VIP
)
)
)
*/
$arrKeys['rt_default_price'] = $this->reservations_model->pop_room_price(); /* This is the 2nd Array:
Array
(
[rt_default_price] => Array
(
[0] => Array
(
[rt_default_price] => 50000
)
[1] => Array
(
[rt_default_price] => 25000
)
[2] => Array
(
[rt_default_price] => 75000
)
[3] => Array
(
[rt_default_price] => 100000
)
)
)
*/
$combined=array();
foreach ($arrKeys as $i => $key) {
$combined[] = array($key => $arrVals[$i]); // Line 24
}
/*echo "<pre>";
print_r($combined);
echo "</pre>";
Array
(
[0] => Array
(
)
)
*/
$this->load->view('/main/new_reservation', $combined);
查看 (main/new_reservation.php)
<?php
echo form_dropdown('room_type', $combined);
?>
模型(reservation_model.php)
function pop_room_type() {
$this->db->select('rt_name');
$query=$this->db->get('room_type');
return $query->result_array();
}
function pop_room_price() {
$this->db->select('rt_default_price');
$query=$this->db->get('room_type');
return $query->result_array();
}