Initially, I'm looping out 10 comments from the database. Then, with the SHOWMORE button I'm looping out 4 more comments each time clicked. However, as from the 14th comment, the looped button, CONSENT THIS doesnt work(sort of a vote button)
ideas.php<?php
$postshow = "SELECT * FROM ideas_1 ORDER BY consents DESC LIMIT 10";
$done = mysqli_query($conn, $postshow);
?>
<div class = 'comments'>
<?php
while ($show = mysqli_fetch_assoc($done)) {
$postid = $show['postid'];
$userid = $show['userid'];
$consents = $show['consents'];?>
<?php echo$show['post'];?><br>
<span class = 'counter'><?php echo$show['consents'];?></span> <span>Consents</span>
<?php $asd = "SELECT * FROM consents WHERE dept = 'ideas' and task = '1' and postid = '$postid' and voterid = '$id'";
$doit = mysqli_query($conn, $asd);
$exist = mysqli_num_rows($doit);
if ($exist == 0){ ?>
<button class = 'consents' data-postid = '<?php echo$postid;?>' data-posterid ='<?php echo$userid;?>'
data-voterid = '<?php echo$id;?>' data-consents = '<?php echo$consents;?>' >Consent This</button>
<?php } ?>
<?php }
?>
</div>
<?php
$more = "SELECT * FROM ideas_1";
$more1 = mysqli_query($conn, $more);
if (mysqli_num_rows($more1)>10) {
?>
<button id = 'showmore'>Show more</button>
<?php }?>
<script>
var voterid = "<?php echo $id;?>"
var commentCount = 10;
$(document).ready(function () {
$('.consents').click(function(){
var postid = $(this).data('postid');
var consents = $(this).data('consents');
var posterid = $(this).data('posterid');
$(this).hide();
$.post ("consentsideas.php", {
dept: "ideas",
task: "1",
postid: postid,
voterid: voterid,
consents: consents,
posterid: posterid
});
$(".counter").html(++consents);
});
$(".post_answer").click(function(){
var answer = $(".answer").val();
$.post ("answerideas.php", {
answer: answer,
id: voterid
});
$(".answer").val('');
});
$("#showmore").click(function(){
commentCount = commentCount + 4;
$('.comments').load("load-ideas.php", {
commentNewCount: commentCount
});
});
}
);
</script>
load-ideas.php
<?php
include ('header.php');
if (isset($_SESSION['id'])){
$id = $_SESSION['id'];
} else {
header("Location: index.php");
}
include('dbh.php');
$commentNewCount = $_POST['commentNewCount'];
$postshow = "SELECT * FROM ideas_1 ORDER BY consents DESC LIMIT $commentNewCount";
$done = mysqli_query($conn, $postshow);
while ($show = mysqli_fetch_assoc($done)) {
$postid = $show['postid'];
$userid = $show['userid'];
$consents = $show['consents'];?>
<div class = 'comments'>
<?php echo$show['post'];?><br>
<span class = 'counter'><?php echo$show['consents'];?></span> <span>Consents</span>
<?php $asd = "SELECT * FROM consents WHERE dept = 'ideas' and task = '1' and postid = '$postid' and voterid = '$id'";
$doit = mysqli_query($conn, $asd);
$exist = mysqli_num_rows($doit);
if ($exist == 0){ ?>
<button class = 'consents' data-postid = '<?php echo$postid;?>' data-posterid ='<?php echo$userid;?>'
data-voterid = '<?php echo$id;?>' data-consents = '<?php echo$consents;?>'>Consent This</button>
<?php } ?>
</div>
<?php }
?>
<script>
$(document).ready(function(){
$('.consents').click(function(){
var postid = $(this).data('postid');
var consents = $(this).data('consents');
var posterid = $(this).data('posterid');
$(this).hide();
$.post ("consentsideas.php", {
dept: "ideas",
task: "1",
postid: postid,
voterid: voterid,
consents: consents,
posterid: posterid
});
$(".counter").html(++consents);
});
});
</script>
What am I doing wrong?