From f9d2d6794045d1717c87e46ad309e4db3d2356c5 Mon Sep 17 00:00:00 2001 From: Bruno Date: Fri, 28 Jun 2024 21:36:31 -0300 Subject: [PATCH] =?UTF-8?q?Tela=20consulta=20usu=C3=A1rios=20funcionando;?= =?UTF-8?q?=20Falta=20edita/excluir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/getUsers.php | 39 +++++++++++++++++++++++++++++++++ js/consultaUser.js | 26 ++++++++++++++++++++++ pages/consulta_usr.html | 47 +++------------------------------------- 3 files changed, 68 insertions(+), 44 deletions(-) create mode 100644 controllers/getUsers.php create mode 100644 js/consultaUser.js diff --git a/controllers/getUsers.php b/controllers/getUsers.php new file mode 100644 index 0000000..93ec9e1 --- /dev/null +++ b/controllers/getUsers.php @@ -0,0 +1,39 @@ +getConnection(); + // echo""; + + return $conn; + + } catch (PDOException $e) { + // $client->trackException($e); + error_log("Error connecting to SQL Server: " . $e->getMessage()); + die("Error connecting to SQL Server."); + } +} + +function getUsers(){ + $conn = createDatabaseConnection(); + $query = "SELECT * FROM usuario"; + $stms = $conn->query($query); + $stms->execute(); + + $results = $stms->fetchAll(PDO::FETCH_ASSOC); + return $results; +} + +if ($_SERVER['REQUEST_METHOD'] == 'GET') { + // echo""; + $responseArray = getUsers(); + + echo json_encode($responseArray); +} \ No newline at end of file diff --git a/js/consultaUser.js b/js/consultaUser.js new file mode 100644 index 0000000..20fb8cb --- /dev/null +++ b/js/consultaUser.js @@ -0,0 +1,26 @@ +//Variáveis +const userTableBody = document.getElementById('user-table-body'); + +// Event Listeners +document.addEventListener('DOMContentLoaded', () => { + buscaUsers(); +}) + +const buscaUsers = async () => { + const response = await fetch('../controllers/getUsers.php', { + method: 'GET' + }); + + if (!response.ok) + throw new Error("Error"); + + const data = await response.json(); + data.reverse(); + console.log(data); + + data.forEach((item)=>{ + var row = userTableBody.insertRow(); + row.insertCell().textContent = item.nome; + row.insertCell().textContent = item.email; + }); +} \ No newline at end of file diff --git a/pages/consulta_usr.html b/pages/consulta_usr.html index f5e8f39..a6eada3 100644 --- a/pages/consulta_usr.html +++ b/pages/consulta_usr.html @@ -63,56 +63,15 @@

Consulta de Usuários

Ações - + - + +