I have a ptoblem with sorting $_post
data in codeigniter.
Controller:
public function filter(){
...
$this->model->method($this->request->post);
...
}
Model:
$keys
= $_POST
-data
public function($keys) {
$this->db->select('*');
$this->db->from('table1 t1');
$this->db->join('table2 t2', 't2.id = t1.id', 'left');
if(!empty($keys['value1']){
$this->db->where('t1.column', $keys['value1']);
}
if(!empty($keys['value2']){
$this->db->where('t1.column', $keys['value2']);
}
if($keys['value3'] || $keys['value4'] || $keys['value5']){
$array = array($keys['value3'], $keys['value4'], $keys['value5']);
$this->db->where_in('t2.column', $array);
}
$query = $this->db->get()->result();
return $query;
}
table1
id value1 valu2
1 23 24
2 12 15
table2
t1_id value (this contain value of value3, value4, value5)
2 7
2 19
2 13
2 3
1 7
1 13
1 3
It works, but if set a value3..value5
, then selects all values, not a priority table1
value, I need to to do value1 and value2 it has been a priority before value3..value5
Sry for my bad english, tnx!
For example: products_table
product_id value1 value2
1 13 9
2 13 9
3 14 10
product_to_atributes
product_id atribute_id
1 2
1 3
1 4
2 3
2 4
product_atributes
atribute_id atribute_name
2 atr_name
3 atr_name2
4 atr_name3
I need select list of product, where value1 = '13'
and value2 = '9'
and product_to_atributes.atribute_id IN(2,4)