任何人都可以帮助我检索db数据以及如何在html table.is中查看它。如果不是,那么我给出的编码是正确的请说我该如何给予。为了在html表格中查看它。如何从数据库中检索数据并使用Codeigniter将其显示在html表中
控制器
class edit_content extends CI_Controller {
function edit_content()
{
parent::__construct();
$this->load->model('editcontent_model');
$this->load->helper('url');
$this->load->library('acl');
$this->data = $this->editcontent_model->get_contents();
}
}
查看
<table>
<tr>
<th>Content</th>
</tr>
<?php foreach($this->data as $r): ?>
<tr>
<tr><?php echo $r['content']; ?>
</tr>
<?php endforeach; ?>
<table>
型号
class editcontent_model extends CI_Model {
var $CI;
function editcontent_model(){
parent::__construct();
}
function get_contents() {
$this->db->select('content');
$this->db->from('contents');
$query = $this->db->get();
return $result = $query->result();
$this->load->view('edit_content/edit_content', $result);
}
}
你的主要问题是,你正试图将数据传递到并从您的**模型加载视图**。相反,你想在你的**控制器**中做到这一点。 – Jeemusu
您使用的是什么版本的Codeigniter?如果它是最新版本,则可能需要重新编写类构造函数。 – Jeemusu
查看完整的解决方案:http://www.c-sharpcorner.com/UploadFile/225740/fetch-data-from-database-and-show-in-tabular-format-in-codei/ – Super