Welcome Guest, Not a member yet? Register   Sign In
'OR Like' MySQL - Maybe a bug?
#1

[eluser]N3XT0R[/eluser]
Hello guys,
i am trying currently to get a searching result with a query created by the active records of CI.

here is the sourcecode part that i have implemented:
Code:
$this->db->select("portierung.portid, status, IFNULL(portierungstermin, '-') as portierungstermin, portierungskennung, carriername, IF(msncancel=1,'Ja','Nein') as msncancel, vorname, nachname, type", FALSE);
        $this->db->from("portierung");
        $this->db->join("portierungskennung", "portierung.dnr = portierungskennung.dnr");
        $this->db->join("portiernummern", "portierung.portid = portiernummern.portid", "LEFT");
        $this->db->join("subscriber", "subscriber.subid = portierung.subid");
        $this->db->join("carrier", "portierungskennung.cid = carrier.cid");
        
        if($trunk !== NULL){
            $this->db->join("trunks", "trunks.trunkid = subscriber.trunkid");
            $this->db->where("domain", $trunk);
        }
        
        if($query !== NULL){
            $this->db->or_like("vorname", $query); // problem is here.
            $this->db->like("nachname", $query);
            $this->db->like("strasse", $query);
            $this->db->like("wohnort", $query);
            $this->db->like("firma", $query);
            $this->db->like("e164", $query);
            
        }
        
        $this->db->order_by("portid", "DESC");
        $this->db->order_by("portierungstermin", "DESC");
        
        if($limit !== NULL && $offset !== NULL){
            $this->db->limit($limit, $offset);
        }
        
        /* @var $query CI_DB_RESULT */
        $query = $this->db->get();

So i am trying to get after the first "where" statement a "or_like" statement.
The result of the above sourcecode is:

Code:
SELECT portierung.portid, status, IFNULL(portierungstermin, '-') as portierungstermin, portierungskennung, carriername, IF(msncancel=1, 'Ja', 'Nein') as msncancel, vorname, nachname, type
FROM (`portierung`)
JOIN `portierungskennung` ON `portierung`.`dnr` = `portierungskennung`.`dnr`
LEFT JOIN `portiernummern` ON `portierung`.`portid` = `portiernummern`.`portid`
JOIN `subscriber` ON `subscriber`.`subid` = `portierung`.`subid`
JOIN `carrier` ON `portierungskennung`.`cid` = `carrier`.`cid`
JOIN `trunks` ON `trunks`.`trunkid` = `subscriber`.`trunkid`
WHERE `domain` = 'sip.xyz.example'
AND `vorname` LIKE '%m%' // why is here a "and", when i called the "or_like" method?
AND `nachname` LIKE '%m%'
AND `strasse` LIKE '%m%'
AND `wohnort` LIKE '%m%'
AND `firma` LIKE '%m%'
AND `e164` LIKE '%m%'
ORDER BY `portid` DESC, `portierungstermin` DESC
LIMIT 10

Now im a little bit confused, because i wrote the "or_like" statement after the where statement in my sourcecode.
CI seems to ignore this line and compile the Active record with a "like" and not a "OR xyz LIKE '%m%'".
But i would need a "or_like" to run my query successfull.

Yep, i can take the standard query to solve the problem. But maybe there are a more ideal solution.

I am using the Version 2.1.3.




Messages In This Thread
'OR Like' MySQL - Maybe a bug? - by El Forum - 06-27-2013, 07:22 AM
'OR Like' MySQL - Maybe a bug? - by El Forum - 06-28-2013, 01:09 AM
'OR Like' MySQL - Maybe a bug? - by El Forum - 06-28-2013, 08:07 AM
'OR Like' MySQL - Maybe a bug? - by El Forum - 06-28-2013, 09:58 AM



Theme © iAndrew 2016 - Forum software by © MyBB