None of these approaches is the right one. Let’s assume you’re putting the records like this:
numero | nome
1 | Teste 1
2 | Teste 2
2.1 | Teste
2.1.1 | Outro teste
The solution would be to create two new columns, one to be the new primary key and one with the parent record id:
id | id_pai | numero | nome
1 | null | 1 | Teste 1
2 | null | 2 | Teste 2
3 | 2 | 1 | Teste
4 | 3 | 1 | Outro teste
Obviously, the countryside id_pai
would be a foreign key to the field id
from the same table. The field id
would be the primary key. The number is formed by traversing the record father, grandfather, etc until arriving in a null
and concatenate the field values numero
that are found.
And for the ordering of conditioning factors? I can put more than one field in the MYSQL condional, type ORDER BY (id, number) or are SQL variables in a repetition loop?
– Rick Rodrigues