Answer the question
In order to leave comments, you need to log in
How to choose the right shape?
There are 3 forms under their 'id' . When you click on one of the forms, the value is entered into the database and retrieved back into the php variable. Then 'echo' is displayed. If without a loop, then the value of the selected form will be shown only for the first form, despite the fact that I choose either 'id=2' or 'id=3' . If the loop then the values will go in order as specified in the database.
The question is. How to set the value in the desired form. If it's 'id=3" then 'echo' will be in the form 3 .
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 ('ваш голос учтен');
}
}
});
});
$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>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question