Answer the question
In order to leave comments, you need to log in
How to group elements by sections in Bitrix?
<?
$arSelect = Array("ID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "PREVIEW_TEXT", "NAME", "DATE_ACTIVE_FROM","PROPERTY_*");//IBLOCK_ID и ID обязательно должны быть указаны, см. описание arSelectFields выше
$arFilter = Array("IBLOCK_ID"=>38, "ACTIVE_DATE"=>"Y", "ACTIVE"=>"Y");
$res = CIBlockElement::GetList(Array(), $arFilter, false, Array("nPageSize"=>50), $arSelect);
while($ob = $res->GetNextElement()){
$arFields = $ob->GetFields();
echo "Номер раздела ".$arFields[IBLOCK_SECTION_ID]."</br>Вопрос: ".$arFields[NAME]."<br>Ответ: ".$arFields[PREVIEW_TEXT]."<br><br>";
$arProps = $ob->GetProperties();
//print_r($arProps);
}
?>
Номер раздела 2310
Вопрос: Можно ли вернуть заказ?
Ответ: Да, в течение 14 дней.
Номер раздела 2312
Вопрос: Как часто?
Ответ: Очень часто
Номер раздела 2312
Вопрос: Какие гарантии?
Ответ: 5 лет
Номер раздела 2310
Вопрос: Можно ли вернуть заказ?
Ответ: Да, в течение 14 дней.
Номер раздела 2312
Вопрос: Как часто?
Ответ: Очень часто
<!-- вырезали дубль 2312 -->
Вопрос: Какие гарантии?
Ответ: 5 лет
Answer the question
In order to leave comments, you need to log in
you won’t get by with one request, you will have to do one and one in a loop, which is ugly but not critical
, something like this
$arFilter = Array(
'IBLOCK_ID' => $IBLOCK_ID,
'GLOBAL_ACTIVE' => 'Y',
);
$arSelect = Array(
'ID',
'NAME'
);
$db_list = CIBlockSection::GetList (Array(), $arFilter, false, $arSelect, false);
while ($ar_result = $db_list->GetNext ())
{
$arSections[]= array('ID'=> $ar_result['ID'], 'NAME'=> $ar_result['NAME']);
}
foreach ($arSections as $index => $arSection)
{
$arSelect = Array(
"ID",
"IBLOCK_ID",
"IBLOCK_SECTION_ID",
"PREVIEW_TEXT",
"NAME",
"DATE_ACTIVE_FROM",
"PROPERTY_*"
);
$arFilter = Array(
"IBLOCK_ID" => 38,
"ACTIVE_DATE" => "Y",
"ACTIVE" => "Y",
'IBLOCK_SECTION_ID' => $arSection['ID']
);
$res = CIBlockElement::GetList (Array(), $arFilter, false, Array(), $arSelect);
while ($ob = $res->GetNextElement ())
{
$arItem = $ob->GetFields ();
$arItem['PROPS'] = $ob->GetProperties ();
$arItems[] = $arItem;
}
$arFullSection = $arSection;
$arFullSection['ITEMS'] = $arItems;
$arFullSection[] = $arFullSection;
unset($arItem,$arItems,$arFullSection);
}
But did not try to use the standard grouping feature: arGroupBy (3rd parameter in getList, which you have set to false)
An array of fields to group the element. If the fields are specified, then the selection is grouped by them (in this case, the arSelectFields parameter will be ignored), and the CNT field is added to the result - the number of grouped elements. If you specify an empty array as arGroupBy, the method will return the number of CNT elements by filter. You can group by the fields of the element, as well as by the values of its properties. To do this, you must specify PROPERTY_ as one of the grouping fields, where PROPERTY_CODE is the ID or symbolic code of the property.
Optional. Default is false - records are not grouped.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question