php递归函数的反向结果


reverse results of php recursive function

我已经写了一个php函数来显示类别,所有作品都找到了,但回声显示为反转的样子(椅子/家具/产品),但我需要将其反转成这样(产品/家具/椅子)

    function sitemap($id) { 
    $query_rsCategoryId = "SELECT * FROM categories 
    WHERE category_id = '".$id."'";
    $rsCategoryId = mysql_query($query_rsCategoryId, $connection);
    $row_rsCategoryId = mysql_fetch_assoc($rsCategoryId);
    $parent = $row_rsCategoryId['category_parent'];
    echo '<li><span class="divider">/</span>
    <a href="products.php?category_id='.$row_rsCategoryId['category_id'].'">
    '.$row_rsCategoryId['category_name_en'].' </a>
    </li>';
    if ($parent == 0) {
    exit;
    } else {
    return sitemap($parent);
    }
}

只需稍微修改一下代码。。。

function sitemap($id) { 
   $query_rsCategoryId = "SELECT * FROM categories 
   WHERE category_id = '".$id."'";
   $rsCategoryId = mysql_query($query_rsCategoryId, $connection);
   $row_rsCategoryId = mysql_fetch_assoc($rsCategoryId);
   $parent = $row_rsCategoryId['category_parent'];

   if ($parent != 0) {
      sitemap($parent);
      echo '<li><span class="divider">/</span>';
   } else {
      echo '<li>';
   }
    echo '<a href="products.php?category_id='.$row_rsCategoryId['category_id'].'">
   '.$row_rsCategoryId['category_name_en'].' </a>
   </li>';
}

尝试在查询中使用按desc排序

SELECT * FROM categories 
WHERE category_id = '".$id."' ORDER BY category_name_en DESC