本文介绍了如何获得每个帖子的回复计数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





以下我有一些代码显示讨论板上的3个最新主题。连同图像,线程名称和最后一个活动,我想显示与该线程关联的回复计数。



我有一个数据库表用于回复的线程和数据库表,并且回复链接到名为replyThreadID的列上的线程表(threadID)(FK到threads.threadID。



Hi,

below I have some code that displays the 3 latest threads on a discussion board. Along with an image, the thread name, and the last activity, I want to display a count of the replies associated to that thread.

I have a database table for threads and a database table for replies, and the replies are linked to the threads table (threadID) on a column called replyThreadID (FK to threads.threadID.

$db = Database::getConnection();
			$query = 'SELECT * FROM threads AS t
			JOIN profile AS p ON t.threadBy = p.username
			WHERE t.threadTopic="'.$topic.'"
			ORDER BY lastActive DESC LIMIT 3';
			$output = $db->query($query);
			$results = $output->fetchAll(PDO::FETCH_ASSOC);
				if (count($results) > 0) {
					echo "<table>\n";
					echo "<tr><th colspan=2>".$topic."</th>
					<th>Replies</th>
					<th>Last activity</th></tr>\n";
					foreach($results as $result){
						$threadID = $result['threadID'];
						//get count of replies for each thread
						$replies = (count());
						$src = $result['image'];
						$image = '<img src="'.$src.'"></img>';
						echo "<tr>\n";
						echo "<td>$image</td>";
						echo "<td>$result[threadName]</td>";
						echo "<td>$replies</td>";
						echo "<td>$result[lastActive]<br>By: $result[threadBy]</td>";
						}
						echo "</tr>\n";
						echo "</table>";
					}
			}





是否可以计算replyThreadID = threadID的回复数量?它应该在foreach内部还是外部?



Is it possible to get a count for the amount of replies where the replyThreadID = threadID? Should it be inside or outside the foreach?

推荐答案




这篇关于如何获得每个帖子的回复计数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-21 03:04