I have a problem with displaying an upvote with js. The application picks up the records in the BD and prints on screen with the upvote on the side, the upvote counter is picking up each new insert in the bd and adding it to the start variable.
index.js
$('.count').each(function() {
var clicks = 0;
$(this).text(clicks);
});
$(".like_button button").on("click", function() {
var $count = $(this).parent().find('.count');
$count.html($count.html() * 1++);
});
$(".deslike_button button").on("click", function() {
var $count = $(this).parent().find('.count');
$count.html($count.html() * 1--);
});
lista.php
<?php
include "php/conecta.php";
$sql = mysqli_query($conexao, "SELECT * FROM tabtexto");
if ($sql === false) {
die(mysqli_error());
}
while ($exibe = mysqli_fetch_assoc($sql)) {
echo "
<script type='text/javascript'>
window.onload = function(){
parent.document.getElementById('test').height = document.getElementById('test').scrollHeight + 35;
}
</script>
<body style='padding-top: 2rem'><div class=' t-0 container'>
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.3/css/bootstrap.min.css' integrity='sha384-Zug+QiDoJOrZ5t4lssLdxGhVrurbmBWopoEl+M6BdEfwnCJZtKxi1KgxUyJq13dy'
crossorigin='anonymous'>
<link rel='stylesheet' href='css/style.css'>
<link rel='stylesheet' href='https://use.fontawesome.com/releases/v5.0.12/css/all.css' integrity='sha384-G0fIWCsCzJIMAVNQPfjH08cyYaUtMwjJwqiRKxxE/rx96Uroj1BtIQ6MLJuheaO9'
crossorigin='anonymous'>
<div class='container t-0'>
<div class='row align-items-center'>
<div class='col-xs text-center'>
<div class='like_button'>
<button class='fas fa-angle-up'>
<span class='count'>0</span>
</button>
</div>
<div class='deslike_button'>
<button class='fas fa-angle-down'>
<span class='count'> 0</span>
</button>
</div>
</div>
<div class='col-sm justify-content-md-center'><h4>
" . $exibe['id'] . ": " . $exibe['texto'] . "</h4></div>
</div>
</div>
</div>
</div>
<hr>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='js/index.js'></script>";
}
mysqli_close($conexao);
?>
Thank you if someone gives me a light.