当我在表格中有 1 条评论时,它不显示任何内容。当我在表格中有 2 条评论时,它只显示第二条。我想由于某种原因它跳过了第一个,有人可以帮忙吗?非常感激 :)
require_once('config.php');
if(!isset($_GET['NewComment'])) {
echo "<a style='float:right;' href='?NewComment' class='btn btn-primary'> New Comment </a> <br /><br />";
$per_page = 4;
$start = 1;
if(!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
if($page <= 1) {
$start = 1;
$page = 1;
} else {
$start = $page * $per_page - $per_page;
}
$next = $page+1;
$previous = $page-1;
$GetAllComments = $con->query("SELECT * FROM comments LIMIT $start, $per_page");
$num_rows = $GetAllComments->num_rows;
$num_pages = $num_rows / $per_page;
while($GAC = $GetAllComments->fetch_object()) {
echo "<div class='well' style='overflow:auto;'> <h3>". $GAC->Title. "</h3>
". $GAC->Content. " <hr /> <em> Posted By ". $GAC->PosterName ." </em>
</div>";
}
for($i = 1; $i <= $num_pages; $i++) {
$pagen = $page+1;
$pagep = $page-1;
echo "
<div class='pagination'>
<ul>
";
if($page > 1) {
echo "
<li><a href='?page=$previous'>".$pagep."</a> </li>
";
}
echo "
<li class='disabled'><a href='#'>$page</a></li>
";
echo "
<li> <a href='?page=$next'>" . $pagen . "</a></li>
</ul>
</div>
";
}
}
elseif(isset($_GET['NewComment'])) {
echo "
<form action='' method='post'>
<h4>First Name:</h4><input type='text' name='fname' placeholder='First Name'>
<h4>Title:</h4><input type='text' name='title' placeholder='Comment Title'>
<textarea name='editor1'><p></p></textarea>
<script>
CKEDITOR.replace( 'editor1' );
</script><br />
<input type='submit' name='post' value='Post' class='btn btn-success'>
</form>
";
if(isset($_POST['post'])) {
$FirstName = $_POST['fname'];
$Title = $_POST['title'];
$Comment = $_POST['editor1'];
$addcomment = $con->prepare("INSERT INTO comments (PosterName, Title, Content) VALUES ('$FirstName','$Title','$Comment')");
$addcomment->execute();
}
}
?>