如何使用codegniter和Php进行数据连接和搜索

时间:2022-10-06 16:42:22

i make a join between two tables using codegniter framework and this is my query:

我使用codegniter框架在两个表之间建立连接,这是我的查询:

public function SearchDataUnderCondition($firsttable,$secondtable,$data)
{

    $this->db->select("atm.* , tender.status as tenderstatus");
    $this->db->from($firsttable);
    $this->db->join($secondtable,'atm.id_tender=tender.id');
    $this->db->where('tenderstatus','1');
    $this->db->like('serial', $data);
    $sql = $this->db->get();
    return $sql->result();

}

i am using database model when is remove

删除时我正在使用数据库模型

$this->db->where('tenderstatus','1');

from my code operation done and i get result but i want to make search under this condition. what is my problem?

从我的代码操作完成,我得到结果,但我想在这种情况下进行搜索。我的问题是什么?

3 个解决方案

#1


1  

Try this

尝试这个

public function SearchDataUnderCondition($data)
{

    $this->db->select('atm.* , tender.status');
    $this->db->from('atm');
    $this->db->join('tender','atm.id_tender=tender.id');
    $this->db->where('tender.status','1');
    $this->db->like('serial', $data);
    $sql = $this->db->get();
    return $sql->result();

}

#2


0  

Try this

尝试这个

$this->db->where('tender.status','1');

I think, we can not aliases in where clause

我想,我们不能在where子句中别名

#3


-2  

Using aliases (and also making sure you want and WHERE AND LIKE clause):

使用别名(并确保你想要和WHERE AND LIKE子句):

        $fist_table = 'atm';
        $second_table = 'tender';

        $this->db->select('aliasone.* , aliastwo.status as "tenderstatus"');
        $this->db->from("$first_table as aliasone");
        $this->db->join("$second_table as aliastwo", "aliastwo.id = aliasone.tender_id");
        $this->db->where('aliastwo.status','1');
        $this->db->like('serial', $data);
        return $this->db->get();

#1


1  

Try this

尝试这个

public function SearchDataUnderCondition($data)
{

    $this->db->select('atm.* , tender.status');
    $this->db->from('atm');
    $this->db->join('tender','atm.id_tender=tender.id');
    $this->db->where('tender.status','1');
    $this->db->like('serial', $data);
    $sql = $this->db->get();
    return $sql->result();

}

#2


0  

Try this

尝试这个

$this->db->where('tender.status','1');

I think, we can not aliases in where clause

我想,我们不能在where子句中别名

#3


-2  

Using aliases (and also making sure you want and WHERE AND LIKE clause):

使用别名(并确保你想要和WHERE AND LIKE子句):

        $fist_table = 'atm';
        $second_table = 'tender';

        $this->db->select('aliasone.* , aliastwo.status as "tenderstatus"');
        $this->db->from("$first_table as aliasone");
        $this->db->join("$second_table as aliastwo", "aliastwo.id = aliasone.tender_id");
        $this->db->where('aliastwo.status','1');
        $this->db->like('serial', $data);
        return $this->db->get();