显示单词Array而不是数据库条目 [英] The word Array is displayed instead of the database entry

查看:55
本文介绍了显示单词Array而不是数据库条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从数据库中打印选定的产品名称,但是我看到的只是单词 Array而不是产品名称。它显示的次数与找到产品的次数相同,并且该数字是正确的,但是只显示数组 ...

I am trying to print selected product names from my database, however all i see is the word "Array" instead of the product name. It is displayed as many times as the number products it finds, and that number is correct, but it only shows "Array"...

这是我的代码:

public function lookup($product)
    {

        $camera = $this->db->query("SELECT name FROM products WHERE type = 'Camera' ");

        $laptop = $this->db->query("SELECT name FROM products WHERE type = 'Laptop' ");


        $data = array();

        switch($product)
        {
            case 'camera' : 
            foreach ($camera->result() as $row)
            {
                $entry = array();
                $entry['name'] = $row->name;
                $data[] = $entry;
            }
            return $data; break;

            case 'laptop' :
            foreach ($laptop->result() as $row)
            {
                $entry = array();
                $entry['name'] = $row->name;
                $data[] = $entry;
            }
            return $data; break;

        }   
    }


推荐答案

您是否要 数组?您可能应该尝试 var_dump($ array_var); 或使用诸如 foreach 之类的循环遍历数组值并打印/回显每个人。

Are you trying to echo an array? You should probably try var_dump($array_var); or use a loop such as foreach to traverse the array values and print/echo each one.

这篇关于显示单词Array而不是数据库条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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