I
I
IgorRastarov2017-01-29 10:58:19
PHP
IgorRastarov, 2017-01-29 10:58:19

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();
   }
   }
?>

How can I now build a loop to display all the elements? By the same name for example.
I thought through foreach
<?foreach ($arFields as $arColor):?>
<?echo $arColor["NAME"]?>
<?endforeach?>

But doesn't work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Burlaka, 2017-01-29
@IgorRastarov

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 question

Ask a Question

731 491 924 answers to any question