Reputation: 151
I'm trying to pass data to my view: model->controller->view.
my model:
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;
}
}
my controller function:
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);
}
and my view:
<?php foreach($records as $record){ ?>
<tr class="gradeA" id="id_65">
<td class="center"><?=$record['id'];?></td>
<td><?=$record['selection'];?></td>
</tr>
<?php } ?>
and after all I receive only nothing meaning numbers (1,1,1,2,4,R,N) so what is wrong with this code?
Upvotes: 0
Views: 81
Reputation: 4079
Change the model like this:
MODEL
class Records_model extends CI_Model {
public function get_records($type){
$this->db->select('*'); // write the column between select like select('id, selection')
$this->db->where('type', $type);
return $this->db->get('records')->$result_array();
}
CONTROLLER
public function basketball(){
$type = 1;
$this->load->model('records_model');
$data['records'] = $this->records_model->get_records($type);
$this->load->view('basketball', $data);
}
VIEW
<?php foreach($records as $record): ?>
<tr class="gradeA" id="id_65">
<td class="center"><?php echo $record['id']; ?></td>
<td><?php $record['selection']; ?></td>
</tr>
<?php endforeach; ?>
Upvotes: 1