TIA.I have two buttons one is Next(#next)
which post the id(PRIMARY/AI)
one at a time from database in a commentbox
(already working). and the Processed(#processed)
which or must delete the row (the id shown in commentbox
)from the database every time it clicks. I have the code : and really sorry if its not good, I'm using Ajax too:
PS: the codes is compilation of many tutorials PS: the processed button (delete) is the only problem here
This the JS:
<script>
//jQuery code here!
$(document).ready(function() {
var commentCount = 0;
$("#next").click(function() {
commentCount += 1;
$("#comments").load("load-comments.php", {
commentNewCount: commentCount
});
$("#processed").removeAttr('disabled');
$(this).attr('disabled', 'disabled');
});
$("#processed").click(function() {
var element = $("#comments");
var commentNewCount = element.attr("commentCount");
var info = 'commentCount=' +commentNewCount;
// alert(info);
if(confirm("Are you sure you want to delete this row?")){
$.ajax({
url: 'deleteuser.php',
type: 'post',
data: info,
success: function(){
}
});
$("#comments").parent().parent().fadeOut(500, function(){
$("#comments").remove();
});
}
return false;
});
$("#next").removeAttr('disabled');
$(this).attr('disabled', 'disabled');
});
</script>
phpcode in Next button:
<?php
include 'dbh.php';
$commentNewCount = $_POST['commentNewCount'];
$sql = "SELECT * FROM comments LIMIT 1 OFFSET $commentNewCount";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo $row['id'];
}
} else {
echo "There are no queue!";
}
?>
phpcode in Processed button:
<?php
include 'dbh.php';
$userid =$_POST['id'];
$delete = mysqli_query($con, "DELETE FROM comments WHERE id=$commentNewCount");
if(!$delete){
echo "The queue Are already Delete" ;
}else{
echo "Success";
}
?>