1
I have the following structure:
I have 3 types of classification, following the coherence: 1.0.0, 1.1.0, 1.1.1, 1.1.2
- I have to display in front of the titles, each content that belongs to its classification, getting the following way in time to display on the screen:
> 1. Meu conteudo Administrativo
> 1.1 Novo Conteudo
> 1.1.1 André Ribeiro
> 1.1.2 Teste de Gestão de Pessoas
You need to follow from every field.
I’m using codeigniter, but it can be done in basic SQL PHP, and I set it in codeigniter.
I tried to do it this way:
$this->db->select("coe_classificacao");
$this->db->where("set_base != ", 12); // conteudo sobre
$this->db->order_by("coe_classificacao", "ASC");
$this->db->group_by("coe_classificacao");
$consulta = $this->db->get('conteudos')->result();
foreach($consulta as &$valor){
$this->db->select("coe_titulo, coe_classificacao, coe_classificacao_1, coe_classificacao_2");
$this->db->where("set_base != ", 12); // conteudo sobre
$this->db->where("coe_classificacao", $valor->coe_classificacao);
$this->db->order_by("coe_classificacao_1", "ASC");
$retorno = $this->db->get('conteudos')->result();
foreach($retorno as &$valor_retorno){
$this->db->select("coe_titulo, coe_classificacao_1, coe_classificacao_2");
$this->db->where("set_base != ", 12); // conteudo sobre
$this->db->where("coe_classificacao_1", $valor_retorno->coe_classificacao_1);
$this->db->order_by("coe_classificacao_2", "ASC");
$valor_retorno->sub = $this->db->get('conteudos')->result();
}
}
But equally, it does not bring me the expected result, I believe you can disregard what I did.
The point is, how do I turn everything into that array, so that I can display it the way I transcribed it?
the method
result()
returns the result inobjetos
orarrays
? Sorry, codeigniter is not my thing...– Kenny Rafael
result is array(), so I give a foreach() if I return Row() it comes as obj
– Sr. André Baill
Maybe it’ll help: Sort Varchar field by taking into account groups and subgroups
– rray