我正在尝试将数据传递给我的视图:模型->控制器->视图。
我的模型:
class Records_model extends CI_Model {
public function get_records($array){
$query = $this->db->select('*')->from('records')->where('type', $array['type'])->get();
foreach ($query->result_array() as $row){
$data = array(
"id" => $row['id'],
"country" => $row['country'],
"event" => $row['event'],
"date" => $row['date'],
"selection" => $row['selection'],
"odds" => $row['odds'],
"result" => $row['result']
);
}
return $data;
}
}
我的控制器功能:
public function basketball(){
$data = array(
"type" => 1
);
$this->load->model('records_model');
$data['records'] = $this->records_model->get_records($data);
$this->load->view('basketball', $data);
}
和我的观点:
<?php foreach($records as $record){ ?>
<tr class="gradeA" id="id_65">
<td class="center"><?=$record['id'];?></td>
<td><?=$record['selection'];?></td>
</tr>
<?php } ?>
毕竟我只收到没有任何意义的数字(1,1,1,2,4,R,N)那么这段代码有什么问题呢?