【发布时间】:2021-07-26 10:11:59
【问题描述】:
我真的不知道如何处理这个问题,事情是,我正在开发一个 Web 应用程序,在一个部分中我需要将项目分配给其他开发人员,每个分配/项目都会优先考虑它的重要性.优先级 1 最高(更重要),优先级 5 最低(不太重要)。
系统要做的是,当我添加新的优先级1(或任何其他优先级)时,如果有其他优先级和优先级1,则将其他优先级向下移动(P1 = P2,P2 = P3,P3 = P4) 并将新的添加为 P1。
我编写了一小段代码(手动制作所有内容,只能运行一次,但仅供您查看我想要的内容)
//PHP CODE
//prioridad = "P1" from a button
$prioridad = validacion::limpiar_cadena($_POST['prioridad']);
$estado = "";
$pes = array();
//I get all the priorities from my user and save them in this array
//Saving an array of the user's priorities
while ($row = $resultado->fetch_assoc()){
$pes[] = $row["prioridad"];
}
//Replace current priorities with their new one (just once)
if (in_array($prioridad, $pes)){
if (in_array("P5", $pes)){
$estado = "lleno";
}
//Make priority 4 = priority 5 and same for all
//This user just had the first 3 priorities,so this one did nothing but the others updated succesfully just for this example
if (in_array("P4", $pes)){
$upd= $conexion->prepare("UPDATE asignarproyectousuario SET prioridad = 'P5' WHERE idUsuario = 1 AND idProyecto = 32");
$upd->execute();
}
if (in_array("P3", $pes)){
$upd= $conexion->prepare("UPDATE asignarproyectousuario SET prioridad = 'P4' WHERE idUsuario = 1 AND idProyecto = 2");
$upd->execute();
}
if (in_array("P2", $pes)){
$upd = $conexion->prepare("UPDATE asignarproyectousuario SET prioridad = 'P3' WHERE idUsuario = 1 AND idProyecto = 1");
$upd->execute();
}
if (in_array("P1", $pes)){
$upd= $conexion->prepare("UPDATE asignarproyectousuario SET prioridad = 'P2' WHERE idUsuario = 1 AND idProyecto = 3");
$upd->execute();
}
$insert = $conexion->prepare("INSERT asignarproyectousuario(idProyecto, idUsuario, prioridad) VALUES(4, 1, ?)");
$insert->bind_param("s", $prioridad);
$insert->execute();
}
我尝试使用数组并将值 1 添加到当前优先级,但我不知道如何使其工作,分离数组并将每个值分配给数据库中的一行。
我还发现队列可以完全“移动”添加一个优先级并按顺序移动其他优先级,但我没有找到太多关于它的文档。
这是我看到的例子:
$queue = new SplQueue();
$queue->enqueue('prioridad1');
$queue->enqueue('Prioridad2');
$queue->enqueue('Prioridad3');
$queue->unshift('prioridad1');
$queue->rewind(); // always rewind the queue/stack, so PHP can start from the beginning.
while($queue->valid()){
echo $queue->current()."\n"; // Show the first one
$queue->next(); // move the cursor to the next element
}
echo "\n"."\n"."\n";
var_dump($queue);
如果你能给我一个如何做的想法或一个不同的例子会非常有帮助。 在此先感谢,如果我的英语不够好,我可以尝试更好地解释它。
【问题讨论】:
标签: javascript php mysql ajax