A quick article on how to use the where clause in a joomla database query.
Why?
In response to a member, I use the old form where I can include the whole SQL statement:
$db->query('SELECT * FROM #__myTable WHERE condition1=true or condition2=true')Method #1 - chain:
$query
->where($db->quoteName('condition1') . ' = '. $db->quote('true'),'OR')
->where($db->quoteName('condition2') . ' = '. $db->quote('true'))
Method #2 - array:
$conditions = array(
$db->quoteName('condition1') . ' = true',
$db->quoteName('condition2') . ' = true'
);
$query->where($conditions, 'OR')
I'd never thought about using all the Or conditions in one variable as i only ever pair two for Or and never combined the two but anything more complex I'd use a full SQL statement with query().
And if i have some AND conditions and some OR conditions?
like this example:
$queryGomme
->select('*') ->from($db->quoteName('table'))
->where($conditionsOr,'OR')
->where($conditions,'AND'));
This doesn't work. The final query has each condition in OR.
Do you have any ideas?
Thanks