Output elements in a certain order — what's wrong?

$cnt_element=1; //we define a numbering
while($ob = $res->GetNextElement()){ //pull out array elements
 $arFields = $ob->GetFields(); //item fields
 $arProps = $ob->GetProperties(); // item properties
....
 //show the elements after the first three from the sample. THE FIRST GROUP
// should be "Элемент4", "Элемент5", "Элемент6"....
if ((empty($arFields[PROPERTY_PHOTOMODULECHECK_VALUE])) and ($cnt_element > 4))
{?><div class="itemsnew-list-item-wrapper"><?=$arFields[NAME]?></div><?}

//show the first 3 elements, but at the end of the list. THE SECOND GROUP
// should be "Item1", "Элемент2", "Элемент3"....
if ((!empty($arFields[PROPERTY_PHOTOMODULECHECK_VALUE])) and ($cnt_element < 4))
{?><div class="itemsnew-list-item-wrapper"><?=$arFields[NAME]?></div><?}

$cnt_element++;
}


The output is a first output of the second group of items, then the first,i.e. like this:
"Control1", "Элемент2", "Элемент3", "Элемент4", "Элемент5", "Элемент6", and not:
"Элемент4", "Элемент5", "Элемент6", "Item1", "Элемент2", "Элемент3".

What I do wrong?
March 23rd 20 at 19:23
1 answer
March 23rd 20 at 19:25
$cnt_element=1; //we define a numbering
$str1 = $str2 = "";
while($ob = $res->GetNextElement()){ //pull out array elements
 $arFields = $ob->GetFields(); //item fields
 $arProps = $ob->GetProperties(); // item properties

//show the elements after the first three from the sample. THE FIRST GROUP
// should be "Элемент4", "Элемент5", "Элемент6"....
if (empty($arFields[PROPERTY_PHOTOMODULECHECK_VALUE]))
{ $str1 .= "<div class='itemsnew-list-item-wrapper'>{$arFields['NAME']}</div>"; }

//show the first 3 elements, but at the end of the list. THE SECOND GROUP
// should be "Item1", "Элемент2", "Элемент3"....
if (!empty($arFields[PROPERTY_PHOTOMODULECHECK_VALUE]))
{ $str2 .= "<div class='itemsnew-list-item-wrapper'>{$arFields['NAME']}</div>"; }

if ($cnt_element == 6)
{ echo($str1.$str2); $str1 = $str2 = ""; $cnt_element = 0; }

$cnt_element++;
}
Oh, and after the loop while(...){...} final echo($str1.$str2);, which would bring the leftovers, when the number of elements will be not a multiple of 6. - gail.Moen46 commented on March 23rd 20 at 19:28

Find more questions by tags PHP