A
A
alexanderks72018-08-03 18:40:52
1C-Bitrix
alexanderks7, 2018-08-03 18:40:52

How to filter CUser::GetList by several indexes at once?

The input field contains a string - full name, email or login. How to get a list of users whose search expression occurs in at least one index?
If I specify

$filter = Array (
    "LOGIN" => 'ключевые | слова',
    "NAME" => 'ключевые | слова',
    "EMAIL" => 'ключевые | слова'
);

then I get an empty result. Apparently, there is a LOGIN & NAME & EMAIL request. How to make a filter "if there is at least one"?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-08-03
Madzhugin @Suntechnic

$filter = Array (
"LOGIC"=>"OR",
   array( "LOGIN" => 'ключевые | слова'),
   array( "NAME" => 'ключевые | слова'),
   array( "EMAIL" => 'ключевые | слова')
);

So it doesn't work?

V
Vasily, 2020-12-22
@yakutec

Unfortunately, only through query

$connection = Bitrix\Main\Application::getConnection();
  $sqlHelper = $connection->getSqlHelper();

  $sql = "SELECT * FROM b_user WHERE
      LOGIN = '".$sqlHelper->forSql($keyw)."'
      OR EMAIL = '".$sqlHelper->forSql($keyw)."' 
      OR NAME = '".$sqlHelper->forSql($keyw)."' 
  ";
  
  $recordset = $connection->query($sql);
  if ($record = $recordset->fetch())
  {

You can learn more about working with query from the course .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question