2014-09-01 25 views
0

您好,我从我的数据库中检索项目时遇到问题,我想只检索一次数据,并且如果某个项目已在之前的值中检索到不显示该项目不要回显以前值中记录的项目

PHP

$select_query = "select * from posts"; 

$run_query = mysql_query($select_query); 
while($row=mysql_fetch_array($run_query)){ 
$post_id = $row['post_id']; 
$post_title = $row['post_title']; 
$post_date = $row['post_date']; 
$post_author = $row['post_author']; 
$post_image = $row['post_image']; 
$post_keywords = $row['post_keywords']; 
$post_content = $row['post_content']; 

HTML

<h1 class="centru">The Posts Author are: <?php echo $post_author; ?> 
</h1> 

EX:在本页面会显示:
JHON
玛丽亚
JHON
亚历
JHON
我想是这样的
JHON
玛丽亚
亚历

回答

1

如果你只是想作者,使用

SELECT DISTINCT post_author FROM posts 
1

使用GROUP BY功能!

$select_query = "select * from `posts` group by `post_author`"; 
相关问题