Answer the question
In order to leave comments, you need to log in
Bitrix, I give up CIBlockElement::SubQuery?
I need to get the name of an element from another infoblock by its id (element) (the id of the element I have is "binding to the element")
Now it's done like this:
$arSelect = Array("ID", "NAME", "PROPERTY_c_serv", "PROPERTY_P_CAT_VALUE");
$arFilter = Array("IBLOCK_ID" => "10");
$res = CIBlockElement::GetList(Array(), $arFilter, false, array("nPageSize" => 25), $arSelect);
while($arFields = $res->fetch()){
//тут я делаю дополнительный запрос
$arSelect_cat = Array("ID", "NAME");
$arFilter_cat = Array("IBLOCK_ID"=>"11", "ACTIVE"=>"Y","ID"=>$arFields["PROPERTY_P_CAT_VALUE"]);
$res_cat = CIBlockElement::GetList(Array(), $arFilter_cat, false, false, $arSelect_cat);
while($ob_cat = $res_cat->GetNextElement()){
$arFields_cat = $ob_cat->GetFields();
$arFields["category"] = $arFields_cat["NAME"];
}
}
$arSelect = Array("ID", "NAME", "PROPERTY_c_serv", "PROPERTY_P_CAT_VALUE");
$arFilter = Array("IBLOCK_ID" => "10", "ID" => CIBlockElement::SubQuery("NAME", array("IBLOCK_ID"=>"11", "ACTIVE"=>"Y","ID"=>$arFields["PROPERTY_P_CAT_VALUE"])));
$res = CIBlockElement::GetList(Array(), $arFilter, false, array("nPageSize" => 25), $arSelect);
while($arFields = $res->fetch()){
//код
}
Answer the question
In order to leave comments, you need to log in
If I understand correctly, you have two IBs on your site. Let's say IB1 and IB2.
In IB1 there is a property of type "Binding to infoblock element". When querying elements from IB1, you want to select the fields of elements from IB2 that are linked to the elements of IB1.
This does not require additional requests.
Opening the documentation on CIblockElement::GetList
Here is what is written there about the selection of such data
PROPERTY_{PROPERTY_CODE}.PROPERTY_{PROPERTY_CODE2} - by property value of the element specified as a binding. PROPERTY_CODE - symbolic code of the element binding type property. PROPERTY_CODE2 - property code of related elements.
Thus, in order to select the name of the attached element in your case, it will be enough to pass PROPERTY_P_CAT.NAME in $arSelect
$arSelect = Array("ID", "NAME", "PROPERTY_c_serv", "PROPERTY_P_CAT_VALUE");
$arFilter = Array("IBLOCK_ID" => "10");
$res = CIBlockElement::GetList(Array(), $arFilter, false, array("nPageSize" => 25), $arSelect);
while($arFields = $res->fetch()){
$ID = $arFields["PROPERTY_P_CAT_VALUE"];
$rest = CIBlockElement::GetByID($ID);
if($ar_rest = $rest->GetNext())
echo $ar_rest['NAME']; // Название элемента
}
Roman Gritsuk
I have such a situation, a selection by number in the proposal.
$arSubQuery = array(
'>CATALOG_QUANTITY' => 0,
);
$arrFilter = array_merge(
array(
'ID' => CIBlockElement::SubQuery('PROPERTY_CML2_LINK', $arSubQuery)
)
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question