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).