codeigniter回显查询结果数组 [英] codeigniter echo query result array

查看:73
本文介绍了codeigniter回显查询结果数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

模型内的方法:

    public function get_fichas(){

    $query = $this->db->query("SELECT * FROM fichas;");

    return $query->result();

}

然后,我正在尝试将此数据传递给控制器。控制器上的方法:

Then, I'm trying to pass this data to the controller. Method on the controller:

public function listar_fichas(){

    $data['fichas_info'] = $this->fichas_model->get_fichas();
    $this->load->view('templates/header');
    $this->load->view('fichas/listar_fichas', $data);

}

当我尝试在视图中列出数据时,我出现以下错误:

When I try to list the data in a view, I get the following error:


致命错误:无法将stdClass类型的对象用作数组

"Fatal error: Cannot use object of type stdClass as array"

这是我尝试列出的方式:

Here is how I'm trying to list:

查看文件:

<?php foreach($fichas_info as $row){?>
    <table>
        <tr>
            <td><?php echo $row['cod_produto'] ;?></td>
            <td><?php echo $row['nome_produto'] ;?></td>
            <td ><?php echo $row['versao'];?></td>
        </tr>
    </table>
<?php }?>

我认为我在视图中做错了。也许我是错误地将数据传递给视图。有人可以告诉我我做错了吗?谢谢!

I think I'm doing something wrong on the view. Perhaps I'm passing the data incorrectly to the view. Can someone please tell what I'm doing wrong? Thank you!

推荐答案

<td><?php echo $row['cod_produto'] ;?></td>
<td><?php echo $row['nome_produto'] ;?></td>
<td><?php echo $row['versao'];?></td>

应为:

<td><?php echo $row->cod_produto ;?></td>
<td><?php echo $row->nome_produto ;?></td>
<td ><?php echo $row->versao;?></td>

结果集是一个对象,因此每个列名称都是该对象的一个​​属性。您正在将它们作为数组的索引进行访问。

The result set is an object, so each column name is a property of the object. You were accessing them as an index of an array.

这篇关于codeigniter回显查询结果数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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