Answer the question
In order to leave comments, you need to log in
How to loop through all elements in Bitrix without using components?
Hello.
I need to display a list of all infoblock elements
and, as a result, work with them.
I don't want to use any components like
new.list, catalog.elemnt etc.
Here is my code
<?
if(CModule::IncludeModule("iblock"))
{
$arSelect = Array("ID", "NAME", "PROPERTY_CODE");
$arFilter = Array("IBLOCK_ID"=>3, "ACTIVE"=>"Y");
$res = CIBlockElement::GetList(Array("SORT"=>"DESC"), $arFilter, false, false, $arSelect);
while($ob = $res->GetNextElement())
{
$arFields = $ob->GetFields();
}
}
?>
<?foreach ($arFields as $arColor):?>
<?echo $arColor["NAME"]?>
<?endforeach?>
Answer the question
In order to leave comments, you need to log in
Perhaps the question should have sounded like this: "I need to get a list of all elements of the infoblock" (because you organized the output directly).
According to your code:
<?
if(CModule::IncludeModule("iblock"))
{
$arSelect = Array("ID", "NAME", "PROPERTY_CODE");
$arFilter = Array("IBLOCK_ID"=>3, "ACTIVE"=>"Y");
$el_tree= array();
$res = CIBlockElement::GetList(Array("SORT"=>"DESC"), $arFilter, false, false, $arSelect);
while($ob_arr = $res->Fetch())
{
$el_tree[ $ob_arr[ 'NAME' ] ]= $ob_arr;
}
foreach ( $el_tree as $el_NAME => $el ) {
echo 'NAME: ', $el_NAME, ' is <pre>', print_r( $el ), '</pre>';
}
}
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question