我想创建一个多级用户脚本,我有以下代码有效,但只显示一个用户线程。我的目标是向每个人展示所有用户,每个组中至少有 3 个子用户。
我有这个:
Maximo Eladio
- Jose Anibal
- Juan De Dios
- Pedro David
- Luis Alberto
- Henry
- Eury Alexander
但我想要这个:
(0)Maximo Eladio
- (1)Jose Anibal
- (2)Juan De Dios
- (3)Pedro David
- (4)Luis Alberto
- (5)Henry
- (6)Eury Alexander
(1)Jose Anibal
- (2)Juan De Dios
- (3)Pedro David
- (4)Luis Alberto
- (5)Henry
- (6)Eury Alexander
(2)Juan De Dios
- (3)Pedro David
- (4)Luis Alberto
- (5)Henry
- (6)Eury Alexander
(3)Pedro David
- (4)Luis Alberto
- (5)Henry
- (6)Eury Alexander
(4)Luis Alberto
- (5)Henry
- (6)Eury Alexander
这实际上是我的代码:
$sql = "SELECT * FROM t_usuarios ";
$results = mysqli_query($con,$sql) or die(mysqli_error()) ;
if($results)
{
while($result = mysqli_fetch_array($results))
{
$category['categories'][$result['id']] = $result;
$category['parent_cats'][$result['id_referido']][] = $result['id'];
}
}
function getCategories($parent, $category)
{
$html = "";
if (isset($category['parent_cats'][$parent]))
{
$html .= "<ul>\n";
foreach ($category['parent_cats'][$parent] as $cat_id)
{
if (!isset($category['parent_cats'][$cat_id]))
{
$html .= "<li>*".$category['categories'][$cat_id]['nombres']."</li> \n";
}
if (isset($category['parent_cats'][$cat_id]))
{
$html .= "<li>". $category['categories'][$cat_id]['nombres'] . " \n";
$html .= getCategories($cat_id, $category);
$html .= "</li> \n";
}
}
$html .= "</ul> \n";
}
return $html;
}
echo $data['category'] = getCategories(0, $category);
请帮助我我该怎么做才能找到路,我尝试了这个但不起作用:
$results2 = mysql_query( "SELECT * FROM t_usuarios ORDER BY id ASC", $link );
while ( $tagrow = mysql_fetch_array( $results2 )){
$sql = "SELECT * FROM t_usuarios WHERE id=".$tagrow["id"]."";
$results = mysqli_query($con,$sql) or die(mysqli_error()) ;
if($results)
{
while($result = mysqli_fetch_array($results))
{
$category['categories'][$result['id']] = $result;
$category['parent_cats'][$result['id_referido']][] = $result['id'];
}
}
function getCategories($parent, $category)
{
$html = "";
if (isset($category['parent_cats'][$parent]))
{
$html .= "<ul>\n";
foreach ($category['parent_cats'][$parent] as $cat_id)
{
if (!isset($category['parent_cats'][$cat_id]))
{
$html .= "<li>*".$category['categories'][$cat_id]['nombres']."</li> \n";
}
if (isset($category['parent_cats'][$cat_id]))
{
$html .= "<li>". $category['categories'][$cat_id]['nombres'] . " \n";
$html .= getCategories($cat_id, $category);
$html .= "</li> \n";
}
}
$html .= "</ul> \n";
}
return $html;
}
echo $data['category'] = getCategories(0, $category);
}