I am trying to get records from same column. I want to get the farm codes from two IDs, I tried following with help of CodeIgniter documentation but it doesn't work.
我正试图从同一列中获得记录。我想从两个id中获取农场代码,我尝试在CodeIgniter文档的帮助下进行跟踪,但它不起作用。
$this->db->select('fa_code');
$this->db->where('fa_id', $by);
$this->db->where('fa_id', $from);
$res=$this->db->get('tukai_farms')->result();
What is wrong? Don't we use AND with same field?
是什么错了吗?我们不是用同一个字段吗?
2 个解决方案
#1
2
You need to declare from where you want to get 'fa_code' then declare the conditions you have:
您需要声明您想从何处获得“fa_code”,然后声明您拥有的条件:
This is the correct way:
这是正确的方法:
public function selectFaCode(){
$by = 1;
$from = 2;
$query = $this->db->select('fa_code')
->from('tukai_farms')
->where('fa_id', $by)
->or_where('fa_id', $from) //Remember that you are declaring the same condition ! Remove this to keep the first where or change the column name if you want to get items from table where the condition is another column.
->get()
->result();
foreach($query as $row){
echo $row->fa_code;
}
}
#2
1
Just as anant said, you should use:
正如anant所说,您应该使用:
$this->db->where('fa_id', $by);
$this->db->or_where('fa_id', $from);
#1
2
You need to declare from where you want to get 'fa_code' then declare the conditions you have:
您需要声明您想从何处获得“fa_code”,然后声明您拥有的条件:
This is the correct way:
这是正确的方法:
public function selectFaCode(){
$by = 1;
$from = 2;
$query = $this->db->select('fa_code')
->from('tukai_farms')
->where('fa_id', $by)
->or_where('fa_id', $from) //Remember that you are declaring the same condition ! Remove this to keep the first where or change the column name if you want to get items from table where the condition is another column.
->get()
->result();
foreach($query as $row){
echo $row->fa_code;
}
}
#2
1
Just as anant said, you should use:
正如anant所说,您应该使用:
$this->db->where('fa_id', $by);
$this->db->or_where('fa_id', $from);