tags:

views:

21

answers:

2

Ciao,

In my forums where I list all the threads, I want also to show links to pages.

Like: http://www.phpbb.com/community/viewforum.php?f=6 (As you can see, it prints the number of pages for the threads that have more than 1 page.)

How should I do so it prints Page 2 if it has more than 10 posts?

I'm not taking about paging, I have that already. I need to print links for pages for all threads.

I store the number of replies a thread has in its table, so its easy to get that but how should I do this? I have paging for posts in the threads, I print 10 posts per page. I guess could make something like

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>

But that's ridiculous there has to be a better way.

My 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

Thanks!

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

that should work

Christian Smorra
How about if there are 10 replies?
Will A
meh...my excuse is that its 1 am here^^
Christian Smorra
+1  A: 

You need a for loop, e.g.

for($replyIndex = 1; $replyIndex <= $num_replies; $replyIndex += 10) {
print "your code for navigating to page here using $replyIndex in the link";
}
Will A
Do not hard-code magic numbers like `10`.
Brock Adams
Not even in noddy sample code?
Will A