如何在数据库中按ID(主键)显示记录,以便在编码器中自动或动态查看


How to display record by ID (primarykey) in database to view automatically or dynamically in codeigniter?

我没有这个问题的 MVC 数据,但您可以通过其他示例帮助我

这是您的控制器作为演示.php:

if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Demo extends CI_Controller    {
    public function __construct(){
        parent::__construct();
    }
    $this->load->model('demo_model');
    $this->load->helper('url');
    function display_content()
    {
        $data   = array();            
        $data['result'] = $this->demo_model->get_records();
        $this->load->view('demo/show_content', $data);
    }
}

您的模型demo_model.php:

    class demo_model extends CI_Model
 {
    function get_records()
    {
        $this->db->select('your tbl columns'); //Ex: u_id,fname,lname
        $this->db->from('your tbl name'); // tbl_user
        $this->db->order_by("title", "desc"); //u_id
        $query = $this->db->get();
        return $result = $query->result();
    }
}

您的视图文件show_content.php:

<table>
<tr>
<th>All Records</th>
</tr>
<?php foreach($result as $res): ?>
<tr><?php echo $res->content; ?></tr>
<?php endforeach; ?>
</table>
?>

这是示例,现在您必须根据需要设置所有参数...