非法的字符串偏移量代码点火器 [英] Illegal string offset codeigniter

查看:75
本文介绍了非法的字符串偏移量代码点火器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我尝试从我的数据库中检索记录,但是在多个字段中,我始终收到此错误严重性:警告消息:字符串偏移量非法".

Hi been trying to retrieve records from my database, but I keep getting this error "Severity: Warning Message: Illegal string offset " in several fields.

这是我的控制器view_logs.php

Here's my controller view_logs.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class View_Logs extends CI_Controller {

function View_Logs()
 {
   parent::__construct();
 }  

function Logs(){
    $id = $this->uri->segment(3);

    $this->load->model('log_listmodel');
    $this->log_listmodel->log_list_get($id);    
}
}
?>

这是我的模型log_listmodel.php

Here's my Model log_listmodel.php

<?php
class Log_Listmodel extends CI_Model{

    function Log_Listmodel()
    {
      parent::__construct();
    }

    function log_list_get($id){
    $query = $this->db->get_where('test_request_log', array('test_request_id' => $id));
    //return $query->result();
    $results=$query->result_array();


    $data['query']=$results[0];
    $this->load->view('logs_list_view',$data);
    }
}
?>

这是我的查看页面log_list_view.php

Here's my view page log_list_view.php

<table class="list_header" bgcolor="#ffffff" border="0" width="1020px" cellpadding="4px">

            <?php foreach($query as $row): ?>
            <tr> 
                <td><b>Updated</b></td>
                <td><?php echo $row['id'];?>.</td>
                <td><?php echo $row['new_testing_reason'];?></td>
                <td><?php echo $row['new_applicant_name'];?></td>
                <td><?php echo $row['new_authorizer_name'];?></td>
                <td><?php echo $row['new_received_by'];?></td>
                <td><?php echo $row['new_test_required'];?></td>
                <td><?php echo $row['new_laboratory_number'];?></td>
                <td><?php echo $row['log_date'];?></td>
                <td><?php echo $row['who'];?></td>
            </tr>
            <?php endforeach; ?>
        </table>

推荐答案

您已经将$data['query']设置为结果的第一行,但是在视图中您正在使用它,因为它将具有整个数据集.

You've set $data['query'] to the first row of your result, but in the view you're using it as it would have the whole data set.

所以您需要更改

$data['query']=$results[0];

$data['query']=$results;

$data['query']=$query->result_array();

这篇关于非法的字符串偏移量代码点火器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆