我无法在查询中获取连接的表值

时间:2017-01-03 09:50:40

标签: codeigniter

Workflow type table

 [Workflow caterory table][2]


public function view_wf_category()
{
            $this->db->select('workflow_category.wf_cat','workflow_type.type_name');
            $this->db->from('workflow_category');
            $this->db->join('workflow_type', 'workflow_type.workflow_type_id = workflow_category.wf_type');
            $query = $this->db->get();
            foreach($query->result_array() AS $row)
            {
                echo $row["wf_cat"]."<br/>";
                echo $row["type_name"]."<br/>";
            }

}

这里我无法打印$ row [“type_name”]并且还显示通知为$ row [“type_name”]的未定义索引。

1 个答案:

答案 0 :(得分:0)

试试这个......

public function view_wf_category()
{
            $this->db->select('workflow_category.wf_cat,workflow_type.type_name')
                   ->from('workflow_category')
                   ->join('workflow_type', 'workflow_type.workflow_type_id = workflow_category.wf_type');
            $query = $this->db->get();
            foreach($query->result_array() as $row)
            {
                echo $row["wf_cat"]."<br/>";
                echo $row["type_name"]."<br/>";
            }

}

此行导致错误..

$this->db->select('workflow_category.wf_cat','workflow_type.type_name');

所以应该只是

$this->db->select('workflow_category.wf_cat,workflow_type.type_name');

在上面的查询中,我使用了查询分组。