它顯示六個帖子,我的數據庫中有6個項目。問題在於它只顯示第一個,並重復五次。這是我第一次編寫PHP,所以請不要太熟悉術語!爲什麼我的PHP while循環重複相同的數據庫結果?
<?php
$pagetitle = "My Portfolio | Projects";
$header = $_SERVER['DOCUMENT_ROOT'];
$header .= "/includes/header.php";
include_once($header);
$sql="SELECT * FROM projects ORDER BY job DESC";
$sql_query=mysql_query($sql);
$post = mysql_fetch_array($sql_query);
$job = $post['job'];
$category = $post['category'];
$title = $post['title'];
$inside = $post['imageinside'];
$outside = $post['imageoutside'];
$body = $post['body'];
$description = $post['description'];
?>
<!-- Blog - Start -->
<?php do {?>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 blog blog_altered blog_left">
<div class="row">
<!-- Blog Image - Start -->
<div class=" col-lg-6 col-md-6 col-sm-10 col-xs-12 pic inviewport animated delay1" data-effect="fadeIn">
<img alt="blog-image" class="img-responsive" src="<?php echo "$outside" ?>">
</div>
<!-- Blog Image - End -->
<!-- Blog Info - Start -->
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12 inviewport animated delay1" data-effect="fadeIn">
<div class="info">
<span class="date"><?php echo "$category" ?></span>
<h4 class="title"><a href="<?php echo "$job" ?>.php"><?php echo "$title" ?></a></h4>
<p><?php echo "$description" ?></p>
<a class="btn btn-primary text-on-primary" href="<?php echo "$job" ?>.php">Read More</a>
</div>
</div>
<!-- Blog Info - End -->
</div>
</div>
<?php } while ($post = mysql_fetch_array($sql_query)) ?>
<!-- Blog - End -->
使用While循環FOR ALL抵達。 – devpro
使用while循環代替while循環。並且不要使用mysql開始使用mysql。* apis – Bhavin