如何从codeigniter中的sql返回行创建多维数组。 从包含$ res中所有值的模型返回值。
Array( [0] => Array
(
[room_id] => 1
[room_no] => 101
[room_desc] => Double Bed Deluxe Non Air Conditioned
[status] => available
[category_id] => 1
[hotel_id] => 1
[tariff_type] => normal
[room_rate] => 1000
[persons] => 0
[date_start] => 0000-00-00
[date_end] => 0000-00-00
[overview_id] => 1
[rom_id] => 1
[hot_id] => 1
[cus_id] => 2
[bok_id] => 2
[dates] => 2017-04-12
)
[1] => Array
(
[room_id] => 2
[room_no] => 101
[room_desc] => Double Bed Deluxe Non Air Conditioned
[status] => available
[category_id] => 1
[hotel_id] => 1
[tariff_type] => normal
[room_rate] => 1000
[persons] => 0
[date_start] => 0000-00-00
[date_end] => 0000-00-00
[overview_id] => 1
[rom_id] => 1
[hot_id] => 1
[cus_id] => 2
[bok_id] => 2
[dates] => 2017-04-13
)
)
我得到这种类型的数据。这种类型无法帮助我。
array(
[0]=>array(
[room_id]=>1
[dates]=>array(
[0]=>2014-04-12
[1]=>2014-04-13
)
)
[1]=>array(
[room_id]=>2
[dates]=>array(
[0]=>2014-04-12
[1]=>2014-04-13
)
)
)
其实我想要这种类型的数据。我可以制作它。请帮助提前谢谢。
|
答案 0 :(得分:0)
您好,您可以尝试使用此代码,这可能会对您有所帮助
$ query = $ this-> db-> get();
$ result = $ query-> result_array();
$ main_array =阵列();
$ actual_array =阵列();
foreach($ result as $ res){
$ main_array [' room_id'] = $ res [' room_id'];
$ main_array ['日期'] =数组($ res [' date_start'],$ res [' date_end']);
$ actual_array [] = $ main_array;
}
// echo"&#34 ;;的print_r($ actual_array);
返回$ actual_array;
答案 1 :(得分:0)
试试这个
// after if ($res) {
for ($i=0; $i < count($res); $i++) {
$res[$i] = array(
'room_id' => $res[$i]['room_id'],
'dates' => array($res[$i]['date_start'],$res[$i]['date_end'])
);
}