Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 1108

General Questions/New to Joomla! 4.x • Re: SQL WHERE clause with two OR conditions

$
0
0
You can pass the "glue" as a second argument.

Code:

$query->where($db->quoteName('column1') . ' LIKE :search1', 'OR')->where($db->quoteName('column2') . ' LIKE :search2')
Note it can only bet set in the first call. To change it later you have to use extendWhere() with first argument as the new outer "glue":

Code:

$query->extendWhere( 'AND', $db->quoteName('column3') . ' LIKE :search3');
This will result in a query like this:

Code:

SELECT * FROM #__table WHERE (`column1` LIKE :search1 OR `column2` LIKE :search2) AND (`column3` LIKE :search3) 
Also, instead of multiple where/extendWhere() calls you can pass an array:

Code:

$query->where(    [        $db->quoteName('column1') . ' LIKE :search1',        $db->quoteName('column2') . ' LIKE :search2',    ],    'OR');

Statistics: Posted by SharkyKZ — Tue Jul 09, 2024 11:08 am



Viewing all articles
Browse latest Browse all 1108

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>