I got trouble importing my own forums data to the phpBB3 forum system. So I wrote a script to repair the binary tree if broken:
Code: Select all
mysql_connect('localhost', 'username', 'password');
mysql_select_db('phpbb');
$c = -1;
$final = array();
function rebuild_children($id)
{
global $c, $final;
// LEFT
$c++;
$left = $c;
$r = mysql_query("SELECT * FROM phpbb_forums WHERE parent_id = $id");
while ($f = mysql_fetch_array($r))
{
rebuild_children($f['forum_id']);
}
// RIGHT
$c++;
$right = $c;
$final[$id] = array('left' => $left, 'right' => $right);
}
rebuild_children(0);
foreach ($final as $k => $f)
{
mysql_query("UPDATE phpbb_forums SET right_id = $f[right], left_id = $f[left] WHERE forum_id = $k");
}