[英]what's wrong with my code to appear database?
help me please, my db is dbindosat and table is formpengajuan请帮帮我,我的数据库是 dbindosat,表是 formpengajuan
my controller我的控制器
<?php
class Crud extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->model('m_data');
$this->load->helper('url');
}
function index(){
$data['filedata'] = $this->m_data->tampil_data()->result();
$this->load->view('viewdata',$data);
}
...
my model我的模特
<?php
class M_data extends CI_Model{
function tampil_data(){
return $this->db->get('formpengajuan');
}
function input_data($data,$table){
$this->db->insert($table,$data);
}
}
my view (viewdata)我的观点(viewdata)
<?php
foreach($filedata as $data){
?>
<tr>
<td><?php echo $data-> kode; ?></td>
<td><?php echo $data-> instansi; ?></td>
<td><?php echo $data-> alamatinstansi; ?></td>
<td><?php echo $data-> judulkegiatan; ?></td>
<td><?php echo $data-> jeniskegiatan; ?></td>
<td><?php echo $data-> dana; ?></td>
<td><?php echo $data-> tanggalacara; ?></td>
<td><?php echo $data-> kontak; ?></td>
<td><?php echo $data-> email; ?></td>
</tr>
<?php } ?>
but messege A PHP Error was encountered Severity: Notice但消息遇到一个 PHP 错误严重性:注意
Message: Undefined variable: filedata消息:未定义变量:文件数据
Filename: views/viewdata.php文件名:views/viewdata.php
and Severity: Warning和严重性:警告
Message: Invalid argument supplied for foreach()消息:为 foreach() 提供的参数无效
Filename: views/viewdata.php文件名:views/viewdata.php
the database does not appear, please help.. thanks数据库没有出现,请帮忙..谢谢
You have to change this line of code in your controller:您必须在控制器中更改这行代码:
function index(){
$data['filedata'] = $this->m_data->tampil_data();
$this->load->view('viewdata',$data);
}
and this in your model code:这在您的模型代码中:
function tampil_data(){
return $this->db->get('formpengajuan')->result();
}
and if you are not auto loading your database then load it in your controllers by adding this lines如果您没有自动加载数据库,则通过添加此行将其加载到控制器中
function __construct(){
parent::__construct();
$this->load->database();
}
Let me know if these changes did help you to solve your problem.如果这些更改确实帮助您解决了问题,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.