我正在尝试在索引页面上显示我的“项目”表的字段内容,但似乎无法使其正常工作。我在这里做错了什么?
型号:
public function prodView() {
$sql = 'SELECT * FROM projects';
$query = $this->db->query($sql);
return $query->result();
}
控制器:
public function index() {
$this->load->model('main_model');
$data ['query'] = $this->main_model->prodView();
$this->load_view('/index', $data);
}
查看:
<?php foreach($query as $row): ?>
<tr>
<td><?php echo $row->project_name; ?></td>
</tr>
<?php endforeach; ?>
答案 0 :(得分:1)
<强>模型强>
public function prodView() {
$result = array();
$this->db->select("*")->from("projects");
$query = $this->db->get();
if($query->num_rows() > 0){
$result = $query->result_array();
}
return $result;
}
<强>控制器强>
public function index() {
$this->load->model('main_model');
$data ['query'] = $this->main_model->prodView();
$this->load->view('missio/index', $data);
}
查看强>
<?php foreach($query as $row): ?>
<tr>
<td><?php echo $row['project_name']; ?></td>
</tr>
<?php endforeach; ?>