Welcome Guest, Not a member yet? Register   Sign In
Write a query with Active Record Class
#1

[eluser]bestmomo[/eluser]
Hello

Is there a way to write this query with pure Active Record Class :

Code:
return $this->db->query("SELECT * FROM content      WHERE  `sectionid` != 'com_weblinks'
             AND `sectionid` != 'com_bibliographie'
             AND `sectionid` != 'com_events'
             AND `sectionid` != 8
             AND `catid` > 67
             AND `state` = 1
           AND (`title` LIKE ".$match."
           OR `introtext` LIKE ".$match."
           OR `fulltext` LIKE ".$match.")
           LIMIT ".$index.",".$limite);

Thanks
#2

[eluser]apodner[/eluser]
This is about as close as I can get. Maybe someone else can get you closer, but I am not sure that you can use Active Record to nest the where clause like you have done here. Not having your db table, I cannot guarantee this will work, but hopefully it will get you on the right track.

Code:
$arrSectionNot = array('com_weblinks', 'com_bibliographie', 'com_events', 8);
$this->db->where_not_in('sectionid', $arrSectionNot);
$this->db->where('catid >', 67);
$this->db->where('state', 1);
$this->db->where("(`title` LIKE ".$match. " OR `introtext` LIKE ".$match."
                    OR `fulltext` LIKE ".$match.")");
$this->db->limit($limite, $index);
$this->db->get('content');
#3

[eluser]bestmomo[/eluser]
Thank you for your answer, it works. I think there is no simple way to get the WHERE with the LIKE items with Active Record Class, unless by writing an extension to DB_active_rec.php.
#4

[eluser]CroNiX[/eluser]
[quote author="bestmomo" date="1355585672"]Thank you for your answer, it works. I think there is no simple way to get the WHERE with the LIKE items with Active Record Class, unless by writing an extension to DB_active_rec.php. [/quote]
The next version of CI, available on GitHub (not complete) has methods for doing what you are wanting. See the "Query Grouping" section here.
#5

[eluser]bestmomo[/eluser]
Thanks for this answer. I looked at next version which has effectively grouping queries with parantheses. I keep my half solution for now. I'll upgrade it when V3 will be stable Wink.
#6

[eluser]apodner[/eluser]
This is the second time this type of question has been posted in the last week or so. I have also worked around it in the past. I believe it can be accomplished by extending the Active Record class (without modding the system core).

https://github.com/AndrewPodner/ci_ar_where_paren

Try the above, it should get the job done




Theme © iAndrew 2016 - Forum software by © MyBB