Answer the question
In order to leave comments, you need to log in
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']);
Answer the question
In order to leave comments, you need to log in
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
$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>';
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question