N
N
Namco2016-05-12 10:17:55
PHP
Namco, 2016-05-12 10:17:55

Update item active date?

Tell me, I'm changing the date of the element's activity, but when you click on the link, it changes for all elements, how to make it change for the one that was clicked.

<? foreach ($arResult["ITEMS"] as $arItem):?>
<a class="up-your-ads-icon" href="#" id="go" onclick="
        <?  
        $newEl = new CIBlockElement;
          $elProps
                = array(
                "MODIFIED_BY"       => $USER->GetID(),       
                "IBLOCK_ID"         => 3,
                "ACTIVE_FROM"       => ConvertTimeStamp(time(), "FULL"),
                "ACTIVE"            => "Y",
               
 
            );
        $res = $newEl->Update($arItem['ID'], $elProps);
        ?> "><?=$arItem['ID']?></a>
 <? endforeach ?>

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexey Zakharov, 2016-05-12
@konratnox

In general, everything is in Google, it seems you have not tried to google

$(".update").click(function(event) {
  var id = $(this).attr('data-id');
  $.ajax({
    url: '/path/to/file',
    type: 'post',
    data: {id: id},
  })
  .done(function() {
    console.log("success");
  })
  .fail(function() {
    console.log("error");
  })
  .always(function() {
    console.log("complete");
  });
  
});

<?
include($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php");
if(\Bitrix\Main\Loader::includeModule('iblock')) {
$newEl = new CIBlockElement;
$elProps = array(
"MODIFIED_BY" => $USER->GetID(), 
"IBLOCK_ID" => 3,
"ACTIVE_FROM" => ConvertTimeStamp(time(), "FULL"),
"ACTIVE" => "Y",
);
$res = $newEl->Update($_REQUEST["id"], $elProps);
}

Something like this, it works or not did not check

D
Denis Gorokhov, 2016-05-12
@gorokhov_dv

You have absolutely no understanding of PHP or JavaScript syntax. Since you are calling - you are updating all the entries in the $arResult["ITEMS"] array. In order to perform an action on click, you must either describe a function for click / onclick that will send an asynchronous request to the server to update the element. Or, on click, submit the form with reloading the page to perform this action.
I advise you to read as an example of implementation .

N
Namco, 2016-05-12
@Namco

Help, I made a request, put it in a file, but the date does not change. What's wrong?

$("#go a").click(updateElement)
  function updateElement()
  {
    $.ajax({
        url: "/local/ajax/edit-ads2.php",
        type: "POST",
        data: requestData,
        cache: false,
        dataType: 'html',
        processData: false,
        contentType: false,
        success: function (data) {
      $('.my-ads-list-container .ads-date').html(data)
                    $('#go').show;
                },
                error: function (error) {
                    console.log('error', error);
                }
    });
  
  }

in the file the following
<?
include($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php");


$newEl = new CIBlockElement;
      $elProps
        = array(
        "MODIFIED_BY"       => $USER->GetID(),       
        "IBLOCK_ID"         => 3,
        "ACTIVE_FROM"       => ConvertTimeStamp(time(), "FULL"),
        "ACTIVE"            => "Y",
         

      );
    $res = $newEl->Update($arItem['ID'], $elProps);

E
Express777, 2016-05-13
@Express777

Namco
Alexey Zakharov wrote the correct answer to you.
I'll just add this:

foreach( $arResul['ITEMS'] as $arItem)
{
?><a class="update" data-id='<?=$arItem['ID']?>' href="">Ссылка примерного вида</a><?
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question