dongzhan5246 2016-10-05 08:38
浏览 77

在获取数据库中的值后,在codeigniter 3中获取未定义的索引返回日期?

I am fetching values from database and the values are successfully shown when i use print_r but i get an error when i try to echo the values out it gives me an error of Message:

Undefined index: return_date

my code for controller is as follows

public function latebooks(){
    $now = date('m/d/Y');
    foreach($table as $q){}
    $table = $q->department_name;
    $table = strtolower($table);

and my code for my model is as follows:

public function timecalculations($table){
    $query= $this->db->get_where('issue_books',array('department_id'=>$table));
    return $query->result_array();

and the code in the view is as follows


 * Created by PhpStorm.
 * User: workspace
 * Date: 05-10-2016
 * Time: 13:46
include 'header.php';
<br /><br />
echo $query['return_date'];
include 'footer.php';

please forgive as i am novice here!Thanks in advance

  • 写回答

4条回答 默认 最新

  • du0173 2016-10-05 08:43

    You are using result() function in your MODEL for getting records, this will return data into object form not in array.


    echo $query['return_date'];

    Should be:

    echo $query->return_date;

    After your modification in your question, you must need to check what are you getting in print_r($run).

    If you have data in multi-dimensional array than you can use loop here, this will print all data either having one record or multiple.

    foreach ($query as $key => $value) {
        echo $value->return_date;

    If you want to use result_array() function than you can use like:

    foreach ($query as $key => $value) {
        echo $value['return_date'];

    This post will help you to understand both functions: codeigniter, result() vs. result_array()

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥500 求解读该段JS代码,需要知道是用干什么的
  • ¥20 qt4代码实现二进制文件读取显示,以及显示的内容进行搜索
  • ¥15 Labview获取LK-G3001数据
  • ¥15 我知道什么是混合树,但是怎么写代码啊
  • ¥50 开发板linux系统安装dpkg,apt函数库 有偿
  • ¥15 浏览器时间循环 交互事件和延时事件的 优先级与执行问题
  • ¥15 GD模块安装出错,libgd无法正常安装
  • ¥20 求有缘人帮我把笛卡尔坐标系转换为经纬度 有偿
  • ¥15 vue2中使用计算属性
  • ¥50 远程桌面打开Mastercam、没有许可证、物理机打开正常