A
A
Artem2020-05-19 17:54:00
PHP
Artem, 2020-05-19 17:54:00

How to highlight a specific shape from duplicate products?

There are 3 products. These products have their own ratings. Let's say the user clicks on the stars of the 3rd rating. Then there is a check and for this user the 3rd rating form is closed or more precisely overlapped in one way or another (by creating a block on top of the form). Here's the solution I'm trying to find. I send data using ajax .

JQUERY
$(".rating-input").on("click", function () {
    var id = $(this).attr("star-attr");// значение каждого инпута по отдельности
    var val = $(this).val();
    $.ajax({
        type: "POST",
        url: "./PHP REQUIRE/addtostars.php",
        data: "id=" + val + "&id1=" + id, // Отправка сразу нескольких значений через ajax
        dataType: "html",
        cache: false,
        success: function (data) { 
            console.log(data);
            if (data >= '0'){
                alert ('вы голосовали');
            } else {
                alert ('ваш голос учтен');
            }
        }
    });
});

PHP
$ra1 = $row['rating']; 
    $checked = intval($ra1); 
    $count = 5; 
    $inputs = '';
    for($i = 1; $i <= $count; $i++) { 
    $checked_attr = $i == $checked ? ' checked' : '';
    $inputs .= '<input  class="rating-input" id="mod' . $i . '' . $row["products_id"] . '" star-attr="' . $row["products_id"] . '" name="radio-rating" type="radio" value="' . $i . '"' . $checked_attr . '>';
    $inputs .= '<label class="rating-star" for="mod' . $i . '' . $row["products_id"] . '" ></label>';
    };

    // вывод
    echo '
    <div  class="order_right">  
     <div  class="wrap_stars">
      <form class="form-rating" method="POST"> // заблокировать форму на которую нажали
      <fieldset class="fieldset">
      <legend></legend>
      <div class="rating-group">

       ' .$inputs . '

      
       </div>
      </fieldset>
        <div class="count_block">
        <!-- Статистика -->
        <ul class="count" >' . $row["rating"] . '</ul>
        </div>
       </form>
      </div>
    </div>

5ec3f2d66d032867769034.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question