Topic on Project:Support desk

selectField with OR group in WHERE condition?

3
Subfader (talkcontribs)

How can I add an OR group condition to the selectField function?

The sql would look like this

  'SELECT `cl_to`
  						FROM `categorylinks`
  						WHERE `cl_from` = '.$catId.'
  						  AND (    `cl_to` = "Foo"
  						        OR `cl_to` = "Bar"
  						        OR `cl_to` = "Baz" )'

But how to get it into the selectField function?

   				$res = $dbr->selectField(
   					'categorylinks',
   					'cl_to',
   					array(
   						'cl_from' => $catId,
   						// ????
       				), __METHOD__
   				);
Ciencia Al Poder (talkcontribs)
(`cl_to` = "Foo" OR `cl_to` = "Bar" OR `cl_to` = "Baz" )

is equivalent to

`cl_to` IN ("Foo", "Bar", "Baz" )

So it should be:

  				$res = $dbr->selectField(
  					'categorylinks',
  					'cl_to',
  					array(
  						'cl_from' => array( $catId, $catId2, $catId3 )
      				), __METHOD__
  				);
Subfader (talkcontribs)

Thanks! I figured out I can also just add string as text instead of an array association.