-1
I’m creating a document request system, and on it is a page that shows all pending requests. These requests are recorded in a Mysql table and shown as in the image below.
The problem is that in the "Actions" field it is only possible to execute something in the order of the table (Borrow or Delete the first one, and then manage to do this with the next one and so on).
Lend = Insert into another table (Mysql) and delete from the table (Mysql) of requests
Delete = Delete from order table
How do I manage to execute the action on any of the list, without having to respect the order of the records shown?
Commands I’m using:
$resultado = mysqli_query($conexao, "SELECT * FROM pedidos ORDER BY 'id'");
$linhas = mysqli_num_rows($resultado);
$linhas1 = mysqli_num_rows($resultado);
Form/Table
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<?php
while($linhas = mysqli_fetch_array($resultado)){
$data = $linhas['dataHora'];
$data = strtotime($data);
echo "<tr>";
/* echo "<td><input type='checkbox' class='checkthis' /></td>";*/
echo "<td></td>";
echo "<td>".$linhas['pasta']."</td>";
echo "<td>".$linhas['codigoPaciente']."</td>";
echo "<td>".$linhas['nomePaciente']."</td>";
echo "<td>".$linhas['motivo']."</td>";
echo "<td>".$linhas['solicitante']."</td>";
echo "<td>".$linhas['setor']."</td>";
echo "<input type='hidden' name='id' value='".$linhas['id_pedidos']."'>";
echo "<td>".date('d/m/Y - H:i', $data)."</td>";
echo "<td> <input type='submit' tittle='Emprestar' value='E' name='SendEmprestar' class='btn btn-sm btn-primary'> <input type='submit' value='A' name='SendDelete' class='btn btn-sm btn-warning'>";
echo "</tr>";
echo "</form>";
}
?>
Process the request
<?php
$SendEmprestar = filter_input(INPUT_POST, 'SendEmprestar', FILTER_SANITIZE_STRING);
if($SendEmprestar){
$id = isset($_POST['id']) ? $_POST['id'] : '';
$resultado = mysqli_query($conexao, "SELECT * FROM pedidos WHERE id_pedidos = $id");
$linhas = mysqli_num_rows($resultado);
$linhas = mysqli_fetch_array($resultado);
$id_pedidos = $linhas['id_pedidos'];
$pasta = $linhas['pasta'];
$nomePaciente = $linhas['nomePaciente'];
$solicitante = $linhas['solicitante'];
$motivo = $linhas['motivo'];
$codigoPaciente = $linhas['codigoPaciente'];
$setor = $linhas['setor'];
$colaborador = isset($_SESSION['nome']) ? $_SESSION['nome'] : '';
$emprestar = "
INSERT INTO emprestados(
pasta,
nomePaciente,
solicitante,
motivo,
codigoPaciente,
setor,
colaborador)
VALUES ('$pasta',
'$nomePaciente',
'$solicitante',
'$motivo',
'$codigoPaciente',
'$setor',
'$colaborador')";
$pendente = "
INSERT INTO pendentes(
pasta,
nomePaciente,
solicitante,
motivo,
codigoPaciente,
setor,
colaborador)
VALUES ('$pasta',
'$nomePaciente',
'$solicitante',
'$motivo',
'$codigoPaciente',
'$setor',
'$colaborador')";
$salvar = mysqli_query($conexao, $emprestar);
$salvar2 = mysqli_query($conexao, $pendente);
if ($salvar and $salvar2 =! 0){
$query = mysqli_query($conexao, "DELETE FROM pedidos WHERE id_pedidos = $id");
if($query != 0){
echo "<div class='alert alert-success' role='alert'>";
echo "Emprestado com sucesso!";
echo "</div>";
echo "<script>deletePedido()</script>";
}else{
echo "Solicitação invalída.";
echo "<script>deletePedido()</script>";
}
}else{
echo "Erro na solicitação!";
echo "<script>deletePedido()</script>";
} }
$SendDelete = filter_input(INPUT_POST, 'SendDelete', FILTER_SANITIZE_STRING);
if($SendDelete){
$id = isset($_POST['id']) ? $_POST['id'] : '';
$query = mysqli_query($conexao, "DELETE FROM pedidos WHERE id_pedidos = $id");
if($query != 0){
echo "<div class='alert alert-warning' role='alert'>";
echo "Pedido excluído com sucesso!";
echo "<script>deletePedido()</script>";
echo "</div>";
}else{
echo "<div class='alert alert-danger' role='alert'>";
echo "Solicitação invalída.";
echo "<script>deletePedido()</script>";
echo "</div>";
}
}
?>
I don’t understand the question. Rephrase, please.
– Renato Souza