A
A
ayapergenov2015-10-13 13:16:33
PHP
ayapergenov, 2015-10-13 13:16:33

How to connect two scripts so that a select is displayed from a php array?

There are two separately working scripts. Is it possible to connect them without knowing the general context of the task? It is necessary that the data from the array be displayed as a list in select
It turned out to display the array in field 2 of the script. But it continues to be displayed as an array and not a list

<select name="<?=$arProperties["FIELD_NAME"]?>" id="<?=$arProperties["FIELD_NAME"]?>" size="<?=$arProperties["SIZE1"]?>">
              
                  <?
                  foreach($arProperties["VARIANTS"] as $arVariants):
                  ?>
                    <option value="<?=$arVariants["VALUE"]?>"<?if ($arVariants["SELECTED"] == "Y") echo " selected";?>><?=$arVariants["NAME"]?>
                      <?
                      global $USER;
                      $arFilter = array("ID" => $USER->GetID());
                      $arParams["SELECT"] = array("UF_TT_ADRESS");
                      $arRes = CUser::GetList($by,$desc,$arFilter,$arParams);
                          if ($res = $arRes->Fetch()) {
                              ?><? print_r($res["UF_TT_ADRESS"])?><?
                          }
                      ?>
                    </option>
                  <?
                  endforeach;
                  ?>
                  
                </select>

1 outputs php array
<?
                      global $USER;
                      $arFilter = array("ID" => $USER->GetID());
                      $arParams["SELECT"] = array("UF_TT_ADRESS");
                      $arRes = CUser::GetList($by,$desc,$arFilter,$arParams);
                          if ($res = $arRes->Fetch()) {
                              ?><pre><? print_r($res["UF_TT_ADRESS"])?></pre><?
                          }
                  ?>

2 is a typical select field from Bitrix
<select name="<?=$arProperties["FIELD_NAME"]?>" id="<?=$arProperties["FIELD_NAME"]?>" size="<?=$arProperties["SIZE1"]?>">
                  <?
                  foreach($arProperties["VARIANTS"] as $arVariants):
                  ?>
                    <option value="<?=$arVariants["VALUE"]?>"<?if ($arVariants["SELECTED"] == "Y") echo " selected";?>><?=$arVariants["NAME"]?></option>
                  <?
                  endforeach;
                  ?>
                  
                </select>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
entermix, 2015-10-13
@entermix

www.php.su/require
www.php.su/include

A
ayapergenov, 2015-10-14
@ayapergenov

Here is a working version with the correct output of the list in the select

<?
global $USER;
$arFilter = array("ID" => $USER->GetID());
$arParams["SELECT"] = array("UF_TT_ADRESS");
$arRes = CUser::GetList($by,$desc,$arFilter,$arParams);
$res = $arRes->Fetch();
?>
<select name="<?=$arProperties["FIELD_NAME"]?>" id="<?=$arProperties["FIELD_NAME"]?>" size="<?=$arProperties["SIZE1"]?>">
 <?
 foreach($res["UF_TT_ADRESS"] as $variant):
 ?>
  <option value="<?=$variant?>"><?=$variant?></option>
 <?
 endforeach;
 ?> 
</select>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question