Php 如何在codeigniter中不同表的两列之间使用逻辑运算符?
如何在CI中不同表的两列之间使用逻辑运算符 我必须检查以下情况:Php 如何在codeigniter中不同表的两列之间使用逻辑运算符?,php,mysql,codeigniter,Php,Mysql,Codeigniter,如何在CI中不同表的两列之间使用逻辑运算符 我必须检查以下情况: $this->db->select('tbl.id ') ->from('tbl') ->join('table','tbl.company_id = table.company_id') ->where('tbl.maxprice >=table.maxprice') ->where('tbl.minprice <= table.minprice')
$this->db->select('tbl.id ')
->from('tbl')
->join('table','tbl.company_id = table.company_id')
->where('tbl.maxprice >=table.maxprice')
->where('tbl.minprice <= table.minprice')
->order_by('tbl.date')
->get()
->row_array();
它显示一个错误:未知列table.maxprice
我如何解决这个问题?谢谢。如果您的表名实际上是table,那么您不应该使用,因为有些关键字是特定于供应商的保留关键字,而table是保留关键字,现在您可以按如下所示重写查询
$this->db->select('t.id ')
->from('tbl t')
->join('table t1', 't.company_id = t1.company_id') /* best is to change your table name from table to something else */
->where('t.maxprice >= t1.maxprice')
->where('t.minprice <= t1.minprice')
->order_by('t.date')
->get()
->row_array();
那样
$this->db->select('tb.id ')
->from('tbl tb')
->join('table','tb.company_id = table.company_id')
->where('tb.maxprice >=table.maxprice')
->where('tb.minprice <= table.minprice')
->order_by('tbl.date')
->get()
->row_array();
你必须使用别名。实际上我在pyrocms中使用它,我有一个类似$fpending=$this->db->select'temp_skshare.id'->from'temp_skshare'->where'temp_skshare.company_id',$compid->join'companyshare',“companyshare.company_id=temp_skshare.company_id”->其中“temp_skshare.maxprice>=companyshare.maxprice”->其中“temp_skshare.minprice@user3094124使用别名->来自“temp_skshare t”->加入“companyshare c”,“c.company_id=t.company_id”在加入和where函数中也不使用完整的表名