如何在论坛中的主题主题旁边打印到页码的直接链接?

时间:2010-07-31 22:50:58

标签: php

侨,

在我列出所有主题的论坛中,我还希望显示指向页面的链接。

喜欢:http://www.phpbb.com/community/viewforum.php?f=6(如您所见,它会打印超过1页的线程的页数。)

如果它有超过10个帖子,我应该如何打印?

我没有采取分页,我已经有了。我需要打印所有线程页面的链接。

我存储了一个线程在其表中的回复数量,因此很容易得到,但我应该怎么做?我在帖子中有帖子的分页,我每页打印10个帖子。我想可能会像

那样
If num_replies > 10 print <link to threads page 1>
If num_replies > 20 print <link to threads page 2>
If num_replies > 30 print <link to threads page 3>
If num_replies > 40 print <link to threads page 4>

但这太荒谬了,必须有更好的方法。

我的SQL:

SELECT t.id,t.poster,t.soggetto, t.posted,t.recentissimo,t.ultimo_id,t.num_views, t.num_replies, t.closed,t.sticky,t.moved_to
FROM threads AS t
WHERE t.forum_id=$id
ORDER BY t.sticky DESC, t.last_post DESC
LIMIT $startIndex, $threadsPerPage

谢谢!

2 个答案:

答案 0 :(得分:1)

你需要一个for循环,例如

for($replyIndex = 1; $replyIndex <= $num_replies; $replyIndex += 10) {
print "your code for navigating to page here using $replyIndex in the link";
}

答案 1 :(得分:0)

$pages = $sql['num_replies']/10;
$i=0;
while($i <= $pages){
 echo "<link to page $i>";
 $i++;
}

应该有效