laserlight has hit it on the head. You should make your queries more streamlined and create a better one
As for the function, I'd do as dagon suggested and add a second parameter, only instead of false, use a counter (default value 0) and add one to it each iteration. That way, you can tell exactly what iteration it is
function someRecursiceFunc($id, $level = 0) {
$level++;
$sql = "SELECT id, parent_id, title FROM some_table WHERE id = ".(int)$id;
$db_result = mysql_query($sql);
while ($row = mysql_fetch_array($db_result)) {
someRecursiveFunc($row['parent_id'], $level);
}
}