1

Topic: viewtopic.php code

I'm new to PunBB. I was looking for a forum to add to the site I am currently working on and somehow found PunBB. I haven't started integrating yet. I was looking at viewtopic.php and saw this part of the code:

    // Determine on what page the post is located (depending on $pun_user['disp_posts'])
    $result = $db->query('SELECT id FROM '.$db->prefix.'posts WHERE topic_id='.$id.' ORDER BY posted') or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());
    $num_posts = $db->num_rows($result);

    for ($i = 0; $i < $num_posts; ++$i)
    {
        $cur_id = $db->result($result, $i);
        if ($cur_id == $pid)
            break;
    }
    ++$i;    // we started at 0

    $_GET['p'] = ceil($i / $pun_user['disp_posts']);

I just think there is no need for the for loop. Add to the WHERE clause of the query: AND posted < $posted where $posted is the posted value of the post. Then $num_posts would be the number of posts before the post $pid. $i above would just be $num_posts + 1.

Thus we eliminate a for loop which can take a while (at least theoretically, although I do not know if it is significant).

Re: viewtopic.php code

but we don't have $posted, so that would mean another query, and is the loop faster or another query faster?

edit: Hmmm actually forget that, it could be selected using the query above.

3

Re: viewtopic.php code

There is a query that I didn't include in my post.

    $result = $db->query('SELECT topic_id FROM '.$db->prefix.'posts WHERE id='.$pid) or error('Unable to fetch post info', __FILE__, __LINE__, $db->error());

posted should be included here.

Re: viewtopic.php code

Cool. I'll put it on the list.

"Programming is like sex: one mistake and you have to support it for the rest of your life."