U
U
unionfourman2016-06-23 16:13:12
PHP
unionfourman, 2016-06-23 16:13:12

How to make GetList show the first element?

There is an output of projects to the map, but it doesn’t work very well
, I have a problem, probably one global one does not display the first element,
a piece of code here

<?
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
if (array_key_exists("code", $_REQUEST) && $_REQUEST["code"]) {
  if(CModule::IncludeModule("iblock")) {
    $code = trim($_REQUEST["code"]);
    $property_enums = CIBlockPropertyEnum::GetList(Array("SORT"=>"ASC"), Array("IBLOCK_ID"=>5, "XML_ID"=>$code));
    while($enum_fields = $property_enums->GetNext())
    {
      $arSort = Array("ID"=>"ASC");
      $arFilter = array (
        "IBLOCK_ID"=> 5,
        "ACTIVE"=> "Y",
        "PROPERTY_AREA"=> $enum_fields['ID'], 
        );
      $arGroupBy = false;
      $arNavStartParams = Array("nTopCount"=>30);
      $arSelect = array("ID" ,"NAME", "PROPERTY_CITY","DETAIL_PICTURE", "DETAIL_PAGE_URL");
      $BDRes = CIBlockElement::GetList(
        $arSort,
        $arFilter,
        $arGroupBy,
        $arNavStartParams,
        $arSelect
        );
      if (!$BDRes->GetNext()) {
        ?>
        <div  class="project-modal-box">
          <div class="project-modal-body clearfix ">
            <div class="project-thumb">
              <img src="http://aoeks.ru/upload/iblock/983/98378e25cb6f533c76033b159928c434.jpg" alt="project-thumb">
              <div class="address">Город</div>
            </div>
            <div class="project-description">
              <div class="project-title"><a href="#">Название проекта</a></div>
              <a href="#" class="readmore">Страница проекта</a>
            </div>
          </div>
        </div>
        <?
      }
      while($arRes = $BDRes->GetNext()) 
      {
        ?>
        <div  class="project-modal-box">
          <div class="project-modal-body clearfix ">
            <div class="project-thumb">
              <img src="<?=CFile::GetPath($arRes["DETAIL_PICTURE"]);?>" alt="project-thumb">
              <div class="address"><?=$arRes["PROPERTY_CITY_VALUE"]?></div>
            </div>
            <div class="project-description">
              <div class="project-title"><a href="<?=$arRes["DETAIL_PAGE_URL"]?>"><?=$arRes["NAME"]?></a></div>

              <a href="<?=$arRes["DETAIL_PAGE_URL"]?>" class="readmore">Страница проекта</a>
            </div>
          </div>
        </div>
        <?
      }
    }
  }
}
?>

Those. if I have only 1 element, it is not displayed(
What's wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
unionfourman, 2016-08-21
@unionfourman

Finally got rid of

if (!$BDRes->GetNext()) {
        ?>
        <div  class="project-modal-box">
          <div class="project-modal-body clearfix ">
            <div class="project-thumb">
              <img src="http://aoeks.ru/upload/iblock/983/98378e25cb6f533c76033b159928c434.jpg" alt="project-thumb">
              <div class="address">Город</div>
            </div>
            <div class="project-description">
              <div class="project-title"><a href="#">Название проекта</a></div>
              <a href="#" class="readmore">Страница проекта</a>
            </div>
          </div>
        </div>
        <?
      }

And empty element via css

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question