J
J
jakiro124012042102021-05-06 12:59:07
1C-Bitrix
jakiro12401204210, 2021-05-06 12:59:07

BItrix how not to display an element if the value in the array is empty?

There is a page on which cities and vacancies are displayed.
Array by which cities are displayed:
6093bdb8a4487726240393.png
How to make it so that elements in which the value "U_VACANCY_CNT" is empty are not displayed (for example, in the screenshot the last element contains an empty U_VACANCY_CNT )?
output component itself:

$rsCities = CIBlockElement::GetList(
  array('SORT' => 'ASC', 'NAME' => 'ASC'),
  array(
    'IBLOCK_ID' => 7,
    'ACTIVE' => 'Y',
  ),
  false,
  false,
  array('ID', 'NAME', 'CODE', 'IBLOCK_SECTION_ID')
);

while($arCity = $rsCities->Fetch()) {
  $arCity['U_VACANCY_CNT'] = $vacanciesGroupedByCity[$arCity['CODE']];
  if($arResult['ITEMS'][$arCity['IBLOCK_SECTION_ID']]) {
    $arResult['ITEMS'][$arCity['IBLOCK_SECTION_ID']]['ITEMS'][] = $arCity;
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2021-05-06
@jakiro12401204210

while($arCity = $rsCities->Fetch()) 
if (!empty($arCity['U_VACANCY_CNT'] ))
{
  $arCity['U_VACANCY_CNT'] = $vacanciesGroupedByCity[$arCity['CODE']];
  if($arResult['ITEMS'][$arCity['IBLOCK_SECTION_ID']]) {
    $arResult['ITEMS'][$arCity['IBLOCK_SECTION_ID']]['ITEMS'][] = $arCity;
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question