H
H
HbIXA2021-01-22 07:14:48
1C-Bitrix
HbIXA, 2021-01-22 07:14:48

How to select 1 element in the infoblock by element property in bitrix?

You need to select 1 element whose field value = 5200014561. Property code BILL. What's wrong? With this code, it displays everything.

$dbData = CIBlockElement::getList(
        array(),
        [
        'IBLOCK_ID' => 230,
        'PROPERTY_BILL' => "5200014561",
        ],
        false, false,
        ['ID', 'IBLOCK_ID', 'PROPERTY_BILL']
    );

    while ($res = $dbData->GetNextElement()) {
        echo "<pre>";
        print_r($res->GetProperties());
        echo "</pre>";
    }

Answer the question

In order to leave comments, you need to log in

4 answer(s)
J
Jupiter Max, 2021-01-22
@vardoLP

maybe try that? 'PROPERTY_BILL_VALUE' => "5200014561",

H
HbIXA, 2021-01-22
@HbIXA

I tried it already, it didn't help, although according to the docks exactly as you described it should work.

R
Roman Nesterenko, 2021-01-22
@nester_87

$arFilter = Array("IBLOCK_ID"=>230, "PROPERTY_BILL" => "5200014561");
$arSelect = Array('ID', 'IBLOCK_ID');
$res = CIBlockElement::GetList(Array("SORT"=>"ASC"), $arFilter, false, array(), $arSelect);

while($ob = $res->GetNextElement()){
  $arFields = $ob->GetFields();
  echo "<pre>";
  print_r($arFields);
  echo "</pre>";
}

I
ivashjke, 2021-01-22
@ivashjke

Do you have this value in the infoblock only for one element in the property or not? if not, then it will display all the elements

$sort = ['ID' => 'ASC'];
$filter = ['IBLOCK_ID' => 230, '=PROPERTY_BILL' => '5200014561']; //тут число еще а не строку попробуйте, хотя это не должно никак повлиять
$select = ['ID', 'IBLOCK_ID', 'PROPERTY_BILL'];
//если элементов несколько с таким значением - это выведет первый
$nTopCount = false;
//$nTopCount = ['nTopCount' => 1]; можно еще так ограничить
$el = CIBlockElement::GetList($sort, $filter, false, $nTopCount, $select)->Fetch();
var_dump($el);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question