我取出由数据库值,并将其成功地所示,当我使用的print_r,但我得到一个错误,当我尝试它给我消息的错误来呼应值:即使在从数据库获取值之后,在codeigniter 3中获取未定义的索引返回日期?
未定义指数:返回的航班
我的控制器代码如下
public function latebooks(){
$now = date('m/d/Y');
$this->load->model('Time');
$id=$this->session->userdata('userid');
$this->load->model('Department');
$table=$this->Department->selecttable($id);
foreach($table as $q){}
$table = $q->department_name;
$table = strtolower($table);
$run=$this->Time->timecalculations($table);
print_r($run);
$this->load->view('Books/datetime',['query'=>$run]);
}
和我对我的模型代码如下:
public function timecalculations($table){
$query= $this->db->get_where('issue_books',array('department_id'=>$table));
return $query->result_array();
}
,并在视图中的代码如下
<?php
/**
* Created by PhpStorm.
* User: workspace
* Date: 05-10-2016
* Time: 13:46
*/
include 'header.php';
?>
<br /><br />
<?php
echo $query['return_date'];
?>
<?php
include 'footer.php';
?>
请在你的模型原谅我的新手我在这里!在此先感谢
是什么'的print_r($运行)的结果;'?在控制器? '$ query-> result()'这会返回对象不是数组 – devpro
@devpro它返回我的输出清楚地显示它像一个数组 –
你在这里犯了一个错误,'foreach($ table as $ q){} $ table = $ q-> department_name; $ table = strtolower($ table);'应该在foreach循环里面或者 使用'$ table = $ table [0] - > department_name' – AHJeebon