I have 3 tables, one with the name of the porter, another with the name of materia, and one with the name of portaria_has_materia. The focus is on the concierge_has_materia. It takes the foreign key fields from the portaria and subject tables along with a field named order, which is the order in which the materials will appear. Staying like this:
tabela portaria_has_materia
id | idportaria | idmateria | ordem |
1 | 6 | 3 | 1 |
2 | 6 | 6 | 2 |
3 | 6 | 5 | 3 |
4 | 6 | 2 | 4 |
The order is always listed in the table, but the items have a correct order to appear in the view, and if they are not in the correct order, I have to place them by changing the order field, because the query will be ordered by he. How can I do to change it and keep the sequence in the database, so that after the change it appears in the correct order?
The return of the data is done in json.
publicfunctiongetMateriaByPortaria(){$this->layout=""; //retornar dados numa tela sem layout
$materias = $this->PortariaMateriaM->get_all_portaria_materia(); //pega todos os dados da tabela portaria_has_materia
$data = array(); //array data
foreach ($materias as $mat) { //foreach que percorre o objeto e armazena no array data
$data[] = array(
"idportaria_materia" => $mat->idportaria_materia,
"ordem" => $mat->ordem,
"numerada" => $mat->numerada,
"idportaria" => $mat->idportaria,
"data_inicio" => $mat->data_inicio,
"data_fim" => $mat->data_fim,
"titulo" => $mat->titulo,
"descricao" => $mat->descricao,
"descricao_internacional" => $mat->descricao_internacional,
"assinatura_instrutor" => $mat->assinatura_instrutor,
"sigla" => $mat->sigla,
"idmateria" => $mat->idmateria,
"nome_materia" => $mat->nome_materia,
"nome_ingles" => $mat->nome_ingles,
"numero_tempo" => $mat->numero_tempo,
"carga_horaria" => $mat->carga_horaria,
"modulo" => $mat->modulo
);
}
print_r(json_encode($data));
return json_encode($data); //retorna dados do array em json
}