Duplicate Items from query
Posted: Sun Sep 28, 2008 5:43 pm
I am new to PHP(only a couple of weeks) and I am trying to make a forum based website with other features. I am wanting to make a query that gets the last 10 topics, and also the 5 most popular topics. Whenever I display the items on the webpage, I get the correct number of results, but they are all duplicates of the last item inserted into the database. The code I have for the last 10 topics is as follows: (The 5 most popular is the same kind of query, so fixing this one wil fix the other one)
the query:
$getPosts = "SELECT Topics.TopicID,Topics.TopicName,Topics.ForumID,Topics.UserID,Topics.PostDate,Topics.PostTime,
Topics.Views,Topics.Replies,Topics.ODBCTime,Users.UserID,Users.User_name FROM Topics INNER JOIN Users ON Topics.UserID = Users.UserID ORDER BY Topics.ODBCTime DESC LIMIT 10";
$retrievePosts = mysql_query($getPosts,$con) or die(mysql_error());
$postRows = mysql_num_rows($retrievePosts);
$postArray = mysql_fetch_array($retrievePosts);
The Display Code
for ($i = 0; $i < $postRows; $i++) {
echo '
<tr>
<td class="tdLeft"><a href="viewtopic.php?forum=' . $postArray["ForumID"] . '&topic=' . $postArray["TopicID"] . '">' . $postArray["TopicName"] . '</a></td>
<td class="tdCenter"><a href="viewprofile.php?user=' . $postArray["UserID"] . '">' . $postArray["User_name"] . '</a></td>
<td class="tdCenter" style="font-size:80%;">' . $postArray["PostDate"] . '<br /> @ ' . $postArray["PostTime"] . '</td>
<td class="tdCenter">' . $postArray["Views"] . '</td>
<td class="tdCenter">' . $postArray["Replies"] . '</td>
</tr>';
}
If anyone could let me know how to make each row display each unique entry, please let me know! Thanks!!
the query:
$getPosts = "SELECT Topics.TopicID,Topics.TopicName,Topics.ForumID,Topics.UserID,Topics.PostDate,Topics.PostTime,
Topics.Views,Topics.Replies,Topics.ODBCTime,Users.UserID,Users.User_name FROM Topics INNER JOIN Users ON Topics.UserID = Users.UserID ORDER BY Topics.ODBCTime DESC LIMIT 10";
$retrievePosts = mysql_query($getPosts,$con) or die(mysql_error());
$postRows = mysql_num_rows($retrievePosts);
$postArray = mysql_fetch_array($retrievePosts);
The Display Code
for ($i = 0; $i < $postRows; $i++) {
echo '
<tr>
<td class="tdLeft"><a href="viewtopic.php?forum=' . $postArray["ForumID"] . '&topic=' . $postArray["TopicID"] . '">' . $postArray["TopicName"] . '</a></td>
<td class="tdCenter"><a href="viewprofile.php?user=' . $postArray["UserID"] . '">' . $postArray["User_name"] . '</a></td>
<td class="tdCenter" style="font-size:80%;">' . $postArray["PostDate"] . '<br /> @ ' . $postArray["PostTime"] . '</td>
<td class="tdCenter">' . $postArray["Views"] . '</td>
<td class="tdCenter">' . $postArray["Replies"] . '</td>
</tr>';
}
If anyone could let me know how to make each row display each unique entry, please let me know! Thanks!!