N
N
Nurshat2015-10-08 00:30:02
PHP
Nurshat, 2015-10-08 00:30:02

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");

which basically works except for the numbering output, at the moment the output looks like this 882d03f09e004e579a1c61f501b993d7.png, but it should look like this, 898acdc4481943b38dcd72bd6ab99fdc.png
please tell me how to do it. I'm not very good at php myself.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Batukhtin, 2015-10-08
@0lorin

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.

P
profesor08, 2015-10-08
@profesor08

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 question

Ask a Question

731 491 924 answers to any question