Answer the question
In order to leave comments, you need to log in
How to output numbering correctly when building a hierarchy tree in php?
Good day, there is a code for building a hierarchy tree written in php
function rec($search, $num)
{
global $response;
$i = 0;
foreach ($response as $row) {
$i++;
if ($row["parent"]== $search || $search == "") {
print "<a href =\"article/?$row[id]\" class=\"linkList\">$num.$i. $row[title] </a>";
}
if($row["child"] != "0"){
rec($row["id"], $num.".".$i);
}else{
$search = "";
}
}
}
rec("", "1");
Answer the question
In order to leave comments, you need to log in
Isn't that right for a start?
But still, probably, there will be problems with nesting. Here it is not necessary to be "strong" in php, but in programming in general.
1. Everything is bad with the incoming data.
2. You are bad at programming.
3. Because of 1 and 2, everything is bad with your code.
Organize the data correctly and conveniently, and then write the code.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question