Joomla WHERE clause with OR

What?
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:
copyraw
$db->query('SELECT * FROM #__myTable WHERE condition1=true or condition2=true')
  1.  $db->query('SELECT * FROM #__myTable WHERE condition1=true or condition2=true') 


Method #1 - chain:
copyraw
$query
    ->where($db->quoteName('condition1') . ' = '. $db->quote('true'),'OR')
    ->where($db->quoteName('condition2') . ' = '. $db->quote('true'))
  1.  $query 
  2.      ->where($db->quoteName('condition1') . ' = '$db->quote('true'),'OR') 
  3.      ->where($db->quoteName('condition2') . ' = '$db->quote('true')) 

Method #2 - array:
copyraw
$conditions = array(
    $db->quoteName('condition1') . ' = true', 
    $db->quoteName('condition2') . ' = true'
);
$query->where($conditions, 'OR')
  1.  $conditions = array( 
  2.      $db->quoteName('condition1') . ' = true', 
  3.      $db->quoteName('condition2') . ' = true' 
  4.  )
  5.  $query->where($conditions, 'OR') 
Category: Joomla :: Article: 569

© 2024 Joel Lipman .com. All Rights Reserved.