K
K
Keliorw2021-07-12 15:41:45
1C-Bitrix
Keliorw, 2021-07-12 15:41:45

How to get only 10 elements from an infoblock?

As I understand it logically, if you set the number of elements to be displayed in the 4th parameter, then this should work, but it would work for a site that has pagination. And I have a task to make it so that only 10 elements would be returned to me specifically for the GetList request.
Here is a code example of how I do it:

$arOrder = [
                        'ID' => 'asc'
                    ];
                    $arFilter = [
                        'SECTION_ID'  => $SECTION_ID,
                        'ACTIVE'      => 'Y',
                        '>ID'         => $IdElement
                    ];
                    return CIBlockElement::GetList($arOrder, $arFilter, false, Array("nTopCount"=>10), ['ID', 'NAME', 'IBLOCK_SECTION_ID']);


This is the code inside the function, all variables for filtering are passed to it.
I also tried nPageSize, it doesn't work

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Keliorw, 2021-07-12
@Keliorw

I didn’t figure out how to do this specifically, so I sorted by ID => desc and then generated the array element I needed from the data that I received, inserted it at the beginning of the final array and at the output I received an array in the order I needed and with the ones I needed elements

S
scottparker, 2021-07-12
@scottparker

$result = CIBlockElement::GetList(array('ID' => 'DESC'), array(), false, array('nTopCount' => 10), array('ID'));
while($item = $result->fetch()){
  $items[] = $item['ID'];
}
echo '<pre>' . print_r($items, true) . '</pre>';

everything is ok, it displays ten elements with the highest id
try to insert it (without your filters) - if everything is ok, then check your filters

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question