[如何在函数php中返回编辑结果

问题描述 投票:-4回答:1

picture

enter image description here

我想显示如下所示的输出:

6: /f
/a/b/c/d/e
php function
1个回答
0
投票

您几乎将一些代码放错了位置

$host = 'localhost';
$userdb = 'root';
$senhadb = '';
$database = 'test';
$db = mysqli_connect($host, $userdb, $senhadb,$database);

function ShowSubCats($id,$db) {
$sql = "select * , (select t2.slug from menu t2 where t2.id=t1.parent) as ParentSlug from menu t1 where t1.id='$id'"; 
$results=mysqli_query($db,$sql);
while ($row = mysqli_fetch_assoc($results)){
    $parent_Before = ShowSubCats($row['parent'],$db);
    if (!empty($row['ParentSlug'])){
        echo '/'.$row['ParentSlug'];
    }
    return $row;
}
}

$id = 6;
echo $id.':';
$sql = "SELECT * from menu where id='$id';";
$results = mysqli_query($db,$sql);
while ($row = mysqli_fetch_assoc($results)) {
    $parent = ShowSubCats($row['parent'],$db);
    echo '/'.$parent['label'];
}
echo '<br>';
if (!empty($parent)) print_r($parent);
© www.soinside.com 2019 - 2024. All rights reserved.