我正在尝试从我的数据库中打印选定的产品名称,但是我看到的只是单词“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;
}
}