5
I’m having trouble developing a system that changes a sequence of numbers. I need this sequence to dispose of items in the correct order. When saving an item in the bank, it receives a number for sequence 1, 2, 3... and so on.
I decided to modify and try to explain better, the list below, comes from a database, the first number only shows the id of the bank the second the order in which they were saved, the rest is only description. I want to know how to modify this order by clicking on one of the items. In the photo item 2 is selected, in this case, when I click the up arrow I want 2 to be 1 and 1 to be 2. How can I make this algorithm?
$mo = $maxOrder - 1; //ultima numeração de ordem da materia menos 1
if($ordem == 1){ //se ordem atual for o primeiro registro
$result = $ordem + $mo; //soma-se ortem atual com $mo para ficar por ultimo
}elseif($ordem == $maxOrder){ //ou se ordem for a ultima
$result = $ordem - 1; //subtrai-se por 1 para passar a ser a primeira
}else{
$result = $ordem + 1; //senão soma-se com 1 para subir
}
To rescue this data I send a request through the angular to the Function below, in it, I call the model that makes the select, store the result in an object and then move around the object with a foreach and store the result in data array name. after that return the data via json with json_encode(). Follows the cited code:
public function getMateriaByPortaria()
{
$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
}
The problem you’re having is that when the
ordem
something changes, it repeats with the same? And you want to avoid this so that it looks different?– user45722
that way, they stay the same, I want them to be different, in sequence, 1, 2, 3...
– Flavio Henrique
Does it matter if the order starts with 0 instead of 1? Type 0,1,2,3...
– user45722
If it does not return repeated, yes.
– Flavio Henrique