2011-05-30 20 views
8

¿Cómo se utiliza el símbolo de corchetes en el registro activo de SQL de Codeigniter? p. cómo llevar a caboCodeigniter - soportes con activerecord?

SELECT * FROM `shops` WHERE (`shopid` = '10' OR `shopid` = '11') AND `shopid` <> '18' 
+0

En CI3.0 puede hacerlo http://www.codeigniter.com/userguide3/database/query_builder .html # query-grouping – Calvin

Respuesta

5

creo que se podría hacer algo como:

$where = "(`shopid` = '10' OR `shopid` = '11')"; 

$this->db->where($where) // or statement here 
     ->where('shopid <>', '18') // chaining with AND 
     ->get('shops'); 

No del todo seguro acerca de la sintaxis, estoy escribiendo esto de la parte superior de mi cabeza. Lo veré cuando llegue a casa si esto no funciona.

+0

¿Por qué se modificó esta versión? – cabaret

+0

Esto me ayudó a darle las gracias. – busycoding

1

Sólo puede hacer algo como:

$this->db->select('field')->from('shops')->where("(`shopid` = '10' OR `shopid` = '11'")->where("`shopid` <> '18'"); 
$query = $this->db->get(); 

Usted puede escribir sus propias cláusulas manualmente:

$ donde = "name = 'Juan' y el estado = 'jefe' O estado = 'activo' ";

$ this-> db-> where ($ where);

Fuente: http://www.codeignitor.com/user_guide/database/active_record.html#where

11
$where="(`shopid` = '10' OR `shopid` = '11')"; 

$ this-> db-> donde ($ donde, NULL, FALSO);

y para el uso y condiciones

$this->db->where('shopid <>', '18') 

es decir

$where="(`shopid` = '10' OR `shopid` = '11')"; 
$this->db->where($where, NULL, FALSE); 
$this->db->where('shopid <>', '18') 
1
$this->db->select() 
     ->from('shops') 
     ->where("'(`shopid` = '10' OR `shopid` = '11')") 
     ->where('shopid !=', 18); 

$this->db->get()->result();