Бих направил :
<?php
function getChildren($id=1) {
$sql = mysql_query("SELECT * FROM categories WHERE category_parent = '$id' ORDER BY lft ASC");
echo "<ul>";
while($row = mysql_fetch_array($sql)) {
echo "<li><a href='/{$row['category_safe_name']}/'>{$row['category_name']}</a>";
getChildren($row['category_id']);
echo "</li>";
}
echo "</ul>";
}
getChildren();
?>