无意间删除了一个div标记。并且尝试了一整夜,但找不到它。我也尝试了一些在线工具,但没有成功。我已经用notepad ++数过了,发现22和21,这意味着缺少一个。但是我无法做的是找到这个缺少的结束标记div并将其放置在应该放置的位置。
这是我的密码
<?php require_once('inc/top.php'); ?>
</head>
<body>
<?php require_once('inc/header.php');
$number_of_posts = 3;
if(isset($_GET['page'])){
$page_id = $_GET['page'];
}
else{
$page_id = 1;
}
if(isset($_GET['cat'])){
$cat_id = $_GET['cat'];
$cat_query = "SELECT * FROM categories WHERE id = $cat_id";
$cat_run = mysqli_query($con, $cat_query);
$cat_row = mysqli_fetch_array($cat_run);
$cat_name = $cat_row['category'];
}
if(isset($_POST['search'])){
$search = $_POST['search-title'];
$all_posts_query = "SELECT * FROM posts WHERE status = 'publish'";
$all_posts_query .= " and tags LIKE '%$search%'";
$all_posts_run = mysqli_query($con, $all_posts_query);
$all_posts = mysqli_num_rows($all_posts_run);
$total_pages = ceil($all_posts / $number_of_posts);
$posts_start_from = ($page_id - 1) * $number_of_posts;
}
else{
$all_posts_query = "SELECT * FROM posts WHERE status = 'publish'";
if(isset($cat_name)){
$all_posts_query .= " and categories = '$cat_name'";
}
$all_posts_run = mysqli_query($con, $all_posts_query);
$all_posts = mysqli_num_rows($all_posts_run);
$total_pages = ceil($all_posts / $number_of_posts);
$posts_start_from = ($page_id - 1) * $number_of_posts;
}
?>
<div class="jumbotron jumbotron-fluid">
<div class="container">
<div id="details">
<h1 class="animated fadeInLeft">Amasiatu <span>CMS</span></h1>
<p class="animated fadeInRight">This is my trial CMS. Hopefully it will someday be commercially available and preferred by developers</p>
</div>
</div>
</div>
<section>
<div class="container">
<div class="row">
<div class="col-md-8">
<?php
$slider_query = "SELECT * FROM posts WHERE status = 'publish' ORDER BY id DESC LIMIT 3";
$slider_run = mysqli_query($con, $slider_query);
if(mysqli_num_rows($slider_run) > 0){
$count = mysqli_num_rows($slider_run);
?>
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<?php
for($i = 0; $i < $count; $i++){
if($i == 0){
echo "<li data-target='#carouselExampleIndicators' data-slide-to='".$i."' class='active'></li>";
}
else{
echo "<li data-target='#carouselExampleIndicators' data-slide-to='".$i."'></li>";
}
}
?>
</ol>
<div class="carousel-inner">
<?php
$check = 0;
while($slider_row = mysqli_fetch_array($slider_run)){
$slider_id = $slider_row['id'];
$slider_image = $slider_row['image'];
$slider_title = $slider_row['title'];
$check = $check + 1;
if($check == 1){
echo "<div class='carousel-item active'>";
}
else{
echo "<div class='carousel-item'>";
}
?>
<a href="post.php?post_id=<?php echo $slider_id;?>"><img src="img/<?php echo $slider_image; ?>"</a> class="d-block w-100" alt="slider-1">
<div class="carousel-caption d-none d-md-block">
<h3><?php echo $slider_title; ?></h3>
</div>
</div>
<?php }?>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
<?php
}
if(isset($_POST['search'])){
$search = $_POST['search-title'];
$query = "SELECT * FROM posts WHERE status = 'publish'";
$query .= " and tags LIKE '%$search%'";
$query .= " ORDER BY id DESC LIMIT $posts_start_from, $number_of_posts";
}
else{
$query = "SELECT * FROM posts WHERE status = 'publish'";
if(isset($cat_name)){
$query .= " and categories = '$cat_name'";
}
$query .= " ORDER BY id DESC LIMIT $posts_start_from, $number_of_posts";
}
$run = mysqli_query($con,$query);
if(mysqli_num_rows($run) > 0){
while($row = mysqli_fetch_array($run)){
$id = $row['id'];
$date = getdate($row['date']);
$day = $date['mday'];
$month = $date['month'];
$year = $date['year'];
$title = $row['title'];
$author = $row['author'];
$author_image = $row['author_image'];
$image = $row['image'];
$categories = $row['categories'];
$tags = $row['tags'];
$post_data = $row['post_data'];
$views = $row['views'];
$status = $row['status'];
?>
<div class="post">
<div class="row">
<div class="col-md-2 post-date">
<div class="day"><?php echo $day; ?></div>
<div class="month"><?php echo $month; ?></div>
<div class="year"><?php echo $year; ?></div>
</div>
<div class="col-md-8 post-title">
<a href="post.php?post_id=<?php echo $id; ?>"><h2><?php echo $title; ?></h2></a>
<p>Written by: <span><?php echo ucfirst($author); ?></span></p>
</div>
<div class="col-md-2 profile-picture">
<img src="img/<?php echo $author_image; ?>" alt="profile picture" class="rounded-circle">
</div>
</div>
<a href="post.php?post_id=<?php echo $id; ?>"><img src="img/<?php echo $image; ?>" class="d-block w-100" alt="Featured Image"></a>
<div class="desc">
<?php echo substr($post_data,0,297)."..."; ?>
</div>
<a href="post.php?post_id=<?php echo $id; ?>" class="btn btn-primary">Read More</a>
<div class="bottom">
<span class="fol"><i class="fas fa-folder"></i><a href="#"> <?php echo ucfirst($categories); ?></a></span>|
<span class="com"><i class="fas fa-comment"></i><a href="#"> Comment</a></span>
</div>
</div>
<?php
}
}
else{
echo "<center><h2>No Post Available</h2></center>";
}
?>
<nav id="pagination">
<ul class="pagination">
<?php
for($i = 1; $i <= $total_pages; $i++){
echo "<li class='page-item ".($page_id == $i ? 'active': '')."'><a class='page-link' href='index.php?page=".$i."&".(isset($cat_name)?"cat=$cat_id":"")."'>$i</a></li>";
}
?>
</ul>
</nav>
</div>
<div class="col-md-4">
<?php require_once('inc/sidebar.php'); ?>
</div>
</div>
</div>
</section>
<?php require_once('inc/footer.php'); ?>
答案 0 :(得分:0)
我发现了您的问题,并且您只忘记了关闭图像标签。我要添加这些错误行并进行检查。
以下错误代码:
<a href="post.php?post_id=<?php echo $slider_id;?>">
<img src="img/<?php echo $slider_image; ?>"
</a>
在上面的代码中,图像标记未关闭。
下面的好代码
<a href="post.php?post_id=<?php echo $slider_id;?>">
<img src="img/<?php echo $slider_image; ?>">
</a>
我还删除了在错误位置添加的两个额外的div,并在正确位置添加了一个div。 现在,我在下面添加所有正确的代码,将此代码复制并粘贴到您的项目中。
<?php require_once('inc/top.php'); ?>
</head>
<body>
<?php require_once('inc/header.php');
$number_of_posts = 3;
if(isset($_GET['page'])){
$page_id = $_GET['page'];
}
else{
$page_id = 1;
}
if(isset($_GET['cat'])){
$cat_id = $_GET['cat'];
$cat_query = "SELECT * FROM categories WHERE id = $cat_id";
$cat_run = mysqli_query($con, $cat_query);
$cat_row = mysqli_fetch_array($cat_run);
$cat_name = $cat_row['category'];
}
if(isset($_POST['search'])){
$search = $_POST['search-title'];
$all_posts_query = "SELECT * FROM posts WHERE status = 'publish'";
$all_posts_query .= " and tags LIKE '%$search%'";
$all_posts_run = mysqli_query($con, $all_posts_query);
$all_posts = mysqli_num_rows($all_posts_run);
$total_pages = ceil($all_posts / $number_of_posts);
$posts_start_from = ($page_id - 1) * $number_of_posts;
}
else{
$all_posts_query = "SELECT * FROM posts WHERE status = 'publish'";
if(isset($cat_name)){
$all_posts_query .= " and categories = '$cat_name'";
}
$all_posts_run = mysqli_query($con, $all_posts_query);
$all_posts = mysqli_num_rows($all_posts_run);
$total_pages = ceil($all_posts / $number_of_posts);
$posts_start_from = ($page_id - 1) * $number_of_posts;
}
?>
<div class="jumbotron jumbotron-fluid">
<div class="container">
<div id="details">
<h1 class="animated fadeInLeft">Amasiatu <span>CMS</span></h1>
<p class="animated fadeInRight">This is my trial CMS. Hopefully it will someday be commercially available and preferred by developers</p>
</div>
</div>
</div>
<section>
<div class="container">
<div class="row">
<div class="col-md-8">
<?php
$slider_query = "SELECT * FROM posts WHERE status = 'publish' ORDER BY id DESC LIMIT 3";
$slider_run = mysqli_query($con, $slider_query);
if(mysqli_num_rows($slider_run) > 0){
$count = mysqli_num_rows($slider_run);
?>
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<?php
for($i = 0; $i < $count; $i++){
if($i == 0){
echo "<li data-target='#carouselExampleIndicators' data-slide-to='".$i."' class='active'></li>";
}
else{
echo "<li data-target='#carouselExampleIndicators' data-slide-to='".$i."'></li>";
}
}
?>
</ol>
<div class="carousel-inner">
<?php
$check = 0;
while($slider_row = mysqli_fetch_array($slider_run)){
$slider_id = $slider_row['id'];
$slider_image = $slider_row['image'];
$slider_title = $slider_row['title'];
$check = $check + 1;
if($check == 1){
echo "<div class='carousel-item active'>";
}
else{
echo "<div class='carousel-item'>";
}
?>
<a href="post.php?post_id=<?php echo $slider_id;?>"><img src="img/<?php echo $slider_image; ?>"></a> class="d-block w-100" alt="slider-1">
<div class="carousel-caption d-none d-md-block">
<h3><?php echo $slider_title; ?></h3>
</div>
</div>
<?php }?>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<!-- </div> div removed -->
<?php
}
if(isset($_POST['search'])){
$search = $_POST['search-title'];
$query = "SELECT * FROM posts WHERE status = 'publish'";
$query .= " and tags LIKE '%$search%'";
$query .= " ORDER BY id DESC LIMIT $posts_start_from, $number_of_posts";
}
else{
$query = "SELECT * FROM posts WHERE status = 'publish'";
if(isset($cat_name)){
$query .= " and categories = '$cat_name'";
}
$query .= " ORDER BY id DESC LIMIT $posts_start_from, $number_of_posts";
}
$run = mysqli_query($con,$query);
if(mysqli_num_rows($run) > 0){
while($row = mysqli_fetch_array($run)){
$id = $row['id'];
$date = getdate($row['date']);
$day = $date['mday'];
$month = $date['month'];
$year = $date['year'];
$title = $row['title'];
$author = $row['author'];
$author_image = $row['author_image'];
$image = $row['image'];
$categories = $row['categories'];
$tags = $row['tags'];
$post_data = $row['post_data'];
$views = $row['views'];
$status = $row['status'];
?>
<div class="post">
<div class="row">
<div class="col-md-2 post-date">
<div class="day"><?php echo $day; ?></div>
<div class="month"><?php echo $month; ?></div>
<div class="year"><?php echo $year; ?></div>
</div>
<div class="col-md-8 post-title">
<a href="post.php?post_id=<?php echo $id; ?>"><h2><?php echo $title; ?></h2></a>
<p>Written by: <span><?php echo ucfirst($author); ?></span></p>
</div>
<div class="col-md-2 profile-picture">
<img src="img/<?php echo $author_image; ?>" alt="profile picture" class="rounded-circle">
</div>
</div>
<a href="post.php?post_id=<?php echo $id; ?>"><img src="img/<?php echo $image; ?>" class="d-block w-100" alt="Featured Image"></a>
<div class="desc">
<?php echo substr($post_data,0,297)."..."; ?>
</div>
<a href="post.php?post_id=<?php echo $id; ?>" class="btn btn-primary">Read More</a>
<div class="bottom">
<span class="fol"><i class="fas fa-folder"></i><a href="#"> <?php echo ucfirst($categories); ?></a></span>|
<span class="com"><i class="fas fa-comment"></i><a href="#"> Comment</a></span>
</div>
<!-- </div> div removed-->
<?php
}
}
else{
echo "<center><h2>No Post Available</h2></center>";
}
?>
<nav id="pagination">
<ul class="pagination">
<?php
for($i = 1; $i <= $total_pages; $i++){
echo "<li class='page-item ".($page_id == $i ? 'active': '')."'><a class='page-link' href='index.php?page=".$i."&".(isset($cat_name)?"cat=$cat_id":"")."'>$i</a></li>";
}
?>
</ul>
</nav>
</div>
</div> <!-- div added -->
<div class="col-md-4">
<?php require_once('inc/sidebar.php'); ?>
</div>
</div>
</div>
</section>
<?php require_once('inc/footer.php'); ?>