gpt4 book ai didi

php - 如何使用 CodeIgniter 从数据库中查看记录

转载 作者:行者123 更新时间:2023-11-30 22:05:12 24 4
gpt4 key购买 nike

我尝试按照有关此 site 的教程通过 Code Igniter 从数据库中查看我的记录但它显示错误信息

我可以尝试什么来识别它?

下面是查看“view_inlist.php”的代码

<table class="table table-striped table-bordered">
<tr>
<td><strong>ID</strong></td>
<td><strong>Name</strong></td>
<td><strong>Number</strong></td>
<td><strong>Type</strong></td>
<td><strong>Unit</strong></td>
<td><strong>Date</strong></td>
</tr>
<?php foreach($LIST as $list)
{?>
<tr>
<td><?=$list->ID;?></td>
<td><?=$list->Name;?></td>
<td><?=$list->Letter_Number;?></td>
<td><?=$list->Letter_Type;?></td>
<td><?=$list->Unit;?></td>
<td><?=$list->Date;?></td>
</tr>
<?php }?>
</table>

这是 Controller “Main.php”

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Main extends CI_Controller {
public function check_inList() {
$this->load->model('login');
$query = $this->login->check_inlist();
$data['LIST'] = null;
if($query){
$data['LIST'] = $query;
}
$this->load->view('form/view_inlist', $data);
}
}

这是模型“login.php”

function check_inlist(){                                                 
$this->db->select("ID,Name,Letter_Number,Letter_Type,Unit,Date");
$this->db->from('in_list');
$query = $this->db->get();
return $query->result();
}

enter image description here enter image description here

最佳答案

try this

in controller

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Main extends CI_Controller {

public function __construct() {
parent::__construct();
$this->load->model('login');
}

public function check_inList() {
$data['all_list'] = $this->login->check_inlist();

$this->load->view('form/view_inlist', $data);
}


}





in model

<?php

class Login extends CI_Model {


function check_inlist(){
$this->db->select('*');
$this->db->from('in_list');
$query = $this->db->get();
return $query->result();
}

}

in view page


<?php foreach($all_list as $list) {?>

<tr>

<td><?php echo $list->ID;?></td>
<td><?php echo $list->Name;?></td>
<td><?php echo $list->Letter_Number;?></td>
<td><?php echo $list->Letter_Type;?></td>
<td><?php echo $list->Unit;?></td>
<td><?php echo $list->Date;?></td>
</tr>
<?php }?>

关于php - 如何使用 CodeIgniter 从数据库中查看记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42038416/

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