Don't do this sort of manipulation with PHP. Use your database.
The correct way to do it in PHP would be to store the results in an array:
Code:
<?php
$query = sprintf('SELECT post_id AS id, post_title AS title, post_time AS time
FROM user_posts
WHERE user_email = \'%s\'
ORDER BY post_time DESC
LIMIT 10',
$user_email);
$posts = array();
$rs = mysql_query($query);
while ($row = mysql_fetch_array($rs, MYSQL_ASSOC))
$posts[] = (object)$row;
array_unique($posts);
?>
<?php foreach ($posts as $post): ?>
<div class="recent">
<h1 class="recent_name">
<a href="user/discussion.php?post_id=<?=$post->id ?>">
<?php echo $post->title; ?>
</a>
</h1>
<span class="date">
<?php echo $post->time; ?>
</span>
</div>
<?php endforeach; ?>
However, this is wasteful of both CPU time and memory. Better is to have the database do it:
Code:
<?php
$query = sprintf('SELECT DISTINCT post_id AS id, post_title AS title, post_time AS time
FROM user_posts
WHERE user_email = \'%s\'
ORDER BY post_time DESC
LIMIT 10',
$user_email);
$rs = mysql_query($query);
?>
<?php while (($row = mysql_fetch_array($rs, MYSQL_ASSOC)) && ($post = (object)$row)): ?>
<div class="recent">
<h1 class="recent_name">
<a href="user/discussion.php?post_id=<?=$post->id ?>">
<?php echo $post->title; ?>
</a>
</h1>
<span class="date">
<?php echo $post->time; ?>
</span>
</div>
<?php endwhile; ?>
Bookmarks