A
A
Anton2018-04-25 02:04:54
1C-Bitrix
Anton, 2018-04-25 02:04:54

How to display the number of items in each category?

<?
if (CModule::IncludeModule("iblock")):
$iblock_id = 8;
$my_slider = CIBlockElement::GetList (
Array("CATALOG_QUANTITY" => "ASC"),
Array('ACTIVE' => 'Y', "IBLOCK_ID" => $iblock_id, 
"SECTION_ID" => 2170, "INCLUDE_SUBSECTIONS" => "Y",
">=CATALOG_QUANTITY" => 1,
"!PROPERTY_SERIAL_VALUE" => false,
"!PROPERTY_MAIN_NAME_VALUE" => false,
),
false,
false,
Array(
'NAME',
'CATALOG_PRICE_1',
'CATALOG_GROUP_1',
'CATALOG_QUANTITY',
'PROPERTY_SERIAL',
'PROPERTY_MAIN_NAME',
)
);
$serialValues=array();
$mainValues=array();
while($ar_fields = $my_slider->GetNext())
{
$serialValues[] = $ar_fields['PROPERTY_SERIAL_VALUE'];
$mainValues[] = $ar_fields['PROPERTY_MAIN_NAME_VALUE'];
}
foreach(array_unique($serialValues) as $valueS){
echo "<br>$valueS";
}
$counter = 0; 
foreach(array_unique($mainValues) as $valueM){
echo "<br>$valueM";
$counter++; 
}
echo $counter; 
endif;?>

$valueS will display five unique categories
$valueM will display 79 unique names
Next to each category $valueS print the number of unique names $valueM (elements) included in this category.
I don't know if I phrased it correctly.
Now the screen looks like this:
LG
Samsung
Sony
Panasonic
Mistery
--5--
Модель 3302 LG
Модель 6474 Sony
Модель 6322 LG
Модель 4305 Samsung
Модель 6444 Sony
Модель 6742 LG
Модель 1111 Mistery
Модель 2224 Sony
Модель 9090 LG....
--79--

А надо так:

LG - всего 19
Samsung - всего 2
Sony - всего 20
Panasonic - всего 11
Mistery - всего 27

Итого 79 из 5 категорий

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Ivanov, 2018-04-26
@ZZiliST

What's stopping you from doing so?

foreach(array_unique($serialValues) as $valueS){
echo $valueS;
echo " - ";
echo count($valueS);
echo "<br>"
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question