gpt4 book ai didi

php - 如何在数据库中按ID(主键)显示记录以在codeigniter中自动或动态查看?

转载 作者:行者123 更新时间:2023-11-29 21:21:05 25 4
gpt4 key购买 nike

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

最佳答案

这是您的 Controller Demo.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();
}
}

您的 View 文件为 show_content.php :

<table>
<tr>
<th>All Records</th>

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

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

关于php - 如何在数据库中按ID(主键)显示记录以在codeigniter中自动或动态查看?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35719006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com