Skip to:
Content
Pages
Categories
Search
Top
Bottom

Re: Getting forum page number

@_ck_

Participant

That’s because get_var only gets one item – the first and only.

You want get_results which returns an array.

Actually, even better in this case would be get_col which should return a flat array.

Another trick to use on that query is possibly to include the topic_time as the end in the WHERE clause so that it doesn’t bother to pull up 10,000 topic id’s if the topic you are looking for is in the first 100

global $topic;
$query="SELECT topic_id FROM $bbdb->topics WHERE forum_id=$forum_id and topic_time<=$topic->topic_time ORDER BY topic_time DESC";
$topic_array = $bbdb->get_col($query);

We could take a huge shortcut and a bit of a gamble that no other topic has the same exact topic_time as this one and simply get the position via count, assuming it’s the very last one. Occasionally you might be a page short, or a page too many.

global $topic;
$query="SELECT count(topic_id) as position FROM $bbdb->topics WHERE forum_id=$forum_id and topic_time<=$topic->topic_time ORDER BY topic_time DESC";
$position = $bbdb->get_var($query);

Then you divide position by topics per page and you have the page it’s on.

$page=ceil($position/bb_get_option('page_topics'));
$link=get_topic_link(0,$page);

Skip to toolbar