无法获取mysql数据codeigniter

时间:2013-07-27 18:33:00

标签: php codeigniter

我正在尝试将数据传递到我的视图:model-> controller-> view。

我的模特:

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)所以这段代码出了什么问题?

0 个答案:

没有答案