Код |
---|
<?php // получаем список вакансий $arSelect = array( 'ID', 'NAME', 'PREVIEW_TEXT', 'DETAIL_PAGE_URL', 'IBLOCK_SECTION_ID' ); $arResult = array( ); $arFilter = array ( "IBLOCK_CODE" => 'vacancy', "ACTIVE" => "Y", "ACTIVE_DATE" => "Y", ); $arSort = array ( 'IBLOCK_SECTION_ID' => 'ASC' ); $arItem = array ( ); $rsElements = CIBlockElement::GetList($arSort, $arFilter, false, array("nTopCount"=>10000), $arSelect); // OMG while ( $obElement = $rsElements->GetNextElement() ) { $arElement = $obElement->GetFields(); $arItem[] = array ( 'ID' => $arElement['ID'], 'NAME' => $arElement['NAME'], 'ANONCE' => $arElement['PREVIEW_TEXT'], 'DETAIL_PAGE_URL' => $arElement['DETAIL_PAGE_URL'], 'IBLOCK_SECTION_ID' => $arElement['IBLOCK_SECTION_ID'], ); } $vacancies_old = array ( ); $sql = "SELECT * FROM b_form_answer WHERE FIELD_ID='42'"; // Magic number :) $res = $DB->query ( $sql ); while ( $row = $res->Fetch() ) { $vacancies_old[] = array ( 'name' => $row['MESSAGE'], 'id' => $row['VALUE'] ); } $vacancies_new = array ( ); foreach ( $arItem as $k => $v ) { $vacancies_new[] = array ( 'name' => $v['NAME'], 'id' => $v['ID'] ); } $to_delete = array(); foreach ( $vacancies_old as $k => $v ) { if ( !in_array ( $v, $vacancies_new ) ) $to_delete[] = $v; } $to_insert = array ( ); foreach ( $vacancies_new as $k => $v ) { if ( !in_array ( $v, $vacancies_old ) ) $to_insert[] = $v; } ///// foreach ( $to_delete as $k => $v ) { $sql = "DELETE FROM b_form_answer WHERE FIELD_ID='42' AND MESSAGE='{$v['name']}' AND VALUE='{$v['id']}'"; $DB->query ( $sql ); } foreach ( $to_insert as $k => $v ) { $sql = "INSERT INTO b_form_answer (FIELD_ID, TIMESTAMP_X, MESSAGE, C_SORT, ACTIVE, VALUE, FIELD_TYPE, FIELD_WIDTH, FIELD_HEIGHT, FIELD_PARAM) VALUES (42, NOW(), '{$v['name']}', 0, 'Y', '{$v['id']}', 'dropdown', 0, 0, '')"; $DB->query ( $sql ); } ?> |
Цитата |
---|
Рамиль Юналиев пишет:
Ни каких запросов к БД, задача я бы сказал "бытовая" в api все есть, GetList используйте для формирования массива, <select> foreach($arr as $val) { ?><option VALUE="<?=$val["ID"]?>"><?=$val["NAME"]?></option><? } </select> Примерно так.. там все элементарно, зачем делать запросы к бд? |
Код |
---|
<?$APPLICATION->IncludeComponent( "bitrix:form", "template", Array( .... ) );?> |