Implement user searching
This commit is contained in:
parent
e77f29b393
commit
67417b0bfc
|
@ -97,10 +97,21 @@ function listUsers($pdo) {
|
|||
return $result;
|
||||
}
|
||||
|
||||
function findUser($pdo, string $id) {
|
||||
function fetchUserData($pdo, string $id) {
|
||||
$query = "SELECT * FROM usuario WHERE id=?";
|
||||
$result = $pdo->prepare($query);
|
||||
$result->execute([$id]); $data = $result->fetch();
|
||||
$result->execute([$id]);
|
||||
$data = $result->fetch();
|
||||
return $data;
|
||||
}
|
||||
|
||||
function findUser($pdo, $input) {
|
||||
$input = "%$input%";
|
||||
$query = "SELECT usuario.nombre, usuario.usuario, rol.nombre, usuario.correo, usuario.id, fecha_baja
|
||||
FROM usuario, rol WHERE usuario.rol=rol.codigo AND (usuario.nombre LIKE ? OR usuario.usuario LIKE ? OR usuario.correo LIKE ?)";
|
||||
$result = $pdo->prepare($query);
|
||||
$result->execute([$input, $input, $input]);
|
||||
$data = $result->fetchAll();
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,9 @@
|
|||
include '../database.php';
|
||||
|
||||
$pdo = connectDatabase();
|
||||
$data = findUser($pdo, $_GET["edit"]);
|
||||
?> <form method="post" action="../user_management.php">
|
||||
$data = fetchUserData($pdo, $_GET["edit"]);
|
||||
?>
|
||||
<form method="post" action="../user_management.php">
|
||||
<div class="input-group">
|
||||
<label>Nombre</label>
|
||||
<input type="text" name="nombre" value="<?php echo $data[1]; ?>">
|
||||
|
|
20
src/user.php
20
src/user.php
|
@ -9,6 +9,9 @@
|
|||
<link rel="stylesheet" href="../static/style.css" type="text/css" media="screen" />
|
||||
</head>
|
||||
<body>
|
||||
<div style="text-align: right; margin-top: 20px;">
|
||||
<a href="forms/user_create_form.html" class="create_btn" >Crear</a>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -23,7 +26,13 @@
|
|||
include 'database.php';
|
||||
|
||||
$pdo = connectDatabase();
|
||||
|
||||
if (isset($_GET["search"])) {
|
||||
$list = findUser($pdo, $_GET["search"]);
|
||||
} else {
|
||||
$list = listUsers($pdo);
|
||||
}
|
||||
|
||||
foreach($list as $row) :
|
||||
if(!$row[5]):
|
||||
?>
|
||||
|
@ -43,8 +52,15 @@
|
|||
<?php endforeach ?>
|
||||
<?php closeDatabase($pdo); ?>
|
||||
</table>
|
||||
<div style="text-align: right;">
|
||||
<a href="forms/user_create_form.html" class="create_btn" >Crear</a>
|
||||
<div>
|
||||
<form method="post" action="user_management.php">
|
||||
<div class="search-group">
|
||||
<input type="text" name="search_box" value="">
|
||||
</div>
|
||||
<div class="input-group">
|
||||
<button class="btn" type="submit" name="search" >Buscar</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -26,6 +26,14 @@ function userDeletion(){
|
|||
header('location: user.php');
|
||||
}
|
||||
|
||||
function userFind(){
|
||||
$data = $_POST;
|
||||
$pdo = connectDatabase();
|
||||
findUser($pdo, $data);
|
||||
closeDatabase($pdo);
|
||||
$search = $data["search_box"];
|
||||
header("location: user.php?search=$search");
|
||||
}
|
||||
|
||||
if (isset($_POST["create"])) {
|
||||
userCreation();
|
||||
|
@ -39,3 +47,7 @@ if (isset($_POST["edit"])) {
|
|||
if (isset($_GET["delete"])) {
|
||||
userDeletion();
|
||||
}
|
||||
|
||||
if (isset($_POST["search"])) {
|
||||
userFind();
|
||||
}
|
||||
|
|
|
@ -46,6 +46,12 @@ form {
|
|||
border-radius: 5px;
|
||||
border: 1px solid gray;
|
||||
}
|
||||
|
||||
.search-group input {
|
||||
height: 30px;
|
||||
width: 93%;
|
||||
font-size: 16px;
|
||||
}
|
||||
.btn {
|
||||
padding: 10px;
|
||||
font-size: 15px;
|
||||
|
|
Loading…
Reference in New Issue