codeigniter 如何仅列出活动记录并从中选择?[duplicate]

vx6bjr1n  于 2022-12-06  发布在  其他
关注(0)|答案(2)|浏览(82)

此问题在此处已有答案

CodeIgniter get_where(4个答案)
上个月关门了。
我需要进行查询以仅返回活动记录,在本例中为imo_status == 1
进行此查询的最佳方式是什么?我使用CI3
下面是源代码。

// LISTA OS AGENCIAMENTOS NO BANCO DE DADOS
public function getProperties()
{   

    $this->db->select('*');
    $this->db->from('ci_properties');
    $this->db->where('imo_status' == 1);
        return $this->db->get("ci_properties")->result_array();

    /*$query = $this->db->get("ci_properties");
    return $query->result_array();*/
}
pwuypxnk

pwuypxnk1#

您建立查询,然后不使用它:

return $this->db->get("ci_properties")->result_array();

这将清除查询构建器,基本上从'ci_properties'执行'get all'。要使用您的查询:

$query = $this->db->get();        
return $query->result();

这是因为你已经在'from'部分指定了表,get('table name'),将得到所有。

yyhrrdl8

yyhrrdl82#

我解决了这个

public function getProperties()
{   

    $this->db->select('*');
    $this->db->from('ci_properties');
    $this->db->where('imo_status', 1);
        $query = $this->db->get();        
        return $query->result_array();
}

相关问题