E
E
Evloshevsky Nikolay2018-08-02 16:41:22
1C-Bitrix
Evloshevsky Nikolay, 2018-08-02 16:41:22

Bitrix API. How to display one infoblock element?

The essence of the question is to display the list of elements of the infoblock using the API. Display each element of the infoblock on a separate page. If I was able to display the list, then one element per page with access via URL (my / element /) I can no longer understand how.
This is how I remove all the elements. And how to display 1 element?

<?
if (CModule::IncludeModule("iblock")):
  $test_elements = CIBlockElement::GetList (
    Array("ID" => "ASC"),
    Array("IBLOCK_ID" => 10),
    false,
    false,
    Array('ID', 'NAME', 'DETAIL_PAGE_URL', 'PREVIEW_TEXT', 'DETAIL_TEXT', 'PREVIEW_PICTURE', 'CODE')
  );
 
  while($ar_fields = $test_elements->GetNext())
  {
    $img_path = CFile::GetPath($ar_fields["PREVIEW_PICTURE"]);
    echo urldecode($ar_fields['NAME']." ;<br>".$ar_fields['PREVIEW_TEXT']." ;<br>"."<img src='".$img_path."' alt='' width=50><br><hr>");
  }
  endif;
?>

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
serginhold, 2018-08-02
@serginhold

do not read the documentation, ask on the toaster ..
in GetList 4th parameter you can pass as much as you need

A
Alexander, 2018-08-03
Madzhugin @Suntechnic

It's really not clear what you are asking.
If you need to display one, the first element of the selection, then heed the advice of serginhold - set the limit to 1 element.
And at worst, you can always replace it
with
AND in your code that you brought in to get the same effect - displaying the first element of the selection.
BUT!
You write something about a url and it is unlikely that you need to display the same element (the first one that comes across) on many different pages.
Therefore, your problem is not at all with the fact that you need to show one element instead of several, as you think and ask, but in how to select the element NEEDED for this page.
If you have a page uniquely associated with an element no matter how, then your filter should select one element and even with while you should get the result you want.
Hence the question - in what query variable and what element id are you passing in the page?

A
Alexey Emelyanov, 2018-08-02
@babarun

GetByID
or
GetIBlockElement

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question