我想回来并在我的index.php上使用将在load-comments.php上创建的commentNewCount的值。我怎样才能做到这一点?
$(document).ready(function() {
var commentCount = 2;
$("button").click(function() {
commentCount = commentCount + 2;
$("#comments").load("load-comments.php", {
commentNewCount: commentCount
});
});
});
负载的comments.php
include 'dbh.php';
$commentNewCount = $_POST['commentNewCount'];
$sql = "SELECT * FROM comments LIMIT $commentNewCount";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "
";
echo $row['author'];
echo "
";
echo $row['message'];
echo "
";}
} else {
echo "There are no comments!";
}
?>