09.10
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
1;Jan;Kowalski;jankowalski@example.com
|
||||||
|
2;Anna;Nowak;annanowak@mail.com
|
||||||
|
3;Piotr;Nowak;pnowak@example.pl
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
<?php
|
||||||
|
$db = mysqli_connect('localhost', 'root', '', '3p_1_pacjenci');
|
||||||
|
|
||||||
|
$f = fopen('dane.txt', 'r');
|
||||||
|
|
||||||
|
$query = "INSERT INTO tabela_1 (identyfikator, imie, nazwisko, email) VALUES (?, ?, ?, ?)";
|
||||||
|
$stmt = mysqli_prepare($db, $query);
|
||||||
|
|
||||||
|
$truncate = "TRUNCATE TABLE tabela_1";
|
||||||
|
|
||||||
|
mysqli_query($db, $truncate);
|
||||||
|
|
||||||
|
$id = $imie = $nazwisko = $email = null;
|
||||||
|
mysqli_stmt_bind_param($stmt, 'isss', $id, $imie, $nazwisko, $email);
|
||||||
|
|
||||||
|
mysqli_begin_transaction($db);
|
||||||
|
|
||||||
|
|
||||||
|
$line = 0;
|
||||||
|
while (($row = fgetcsv($f, 0, ';')) !== false) {
|
||||||
|
$line++;
|
||||||
|
|
||||||
|
[$id, $imie, $nazwisko, $email] = array_map('trim', array_slice($row, 0, 4));
|
||||||
|
|
||||||
|
mysqli_stmt_execute($stmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
$selectSql = "SELECT identyfikator, imie, nazwisko, email FROM tabela_1 ORDER BY identyfikator";
|
||||||
|
$res = mysqli_query($db, $selectSql);
|
||||||
|
|
||||||
|
$html = '<table border="1" cellspacing="0">';
|
||||||
|
$html .= '<thead><tr><th>Identyfikator</th><th>Imię</th><th>Nazwisko</th><th>Email</th></tr></thead><tbody>';
|
||||||
|
|
||||||
|
if ($res && mysqli_num_rows($res) > 0) {
|
||||||
|
while ($row = mysqli_fetch_assoc($res)) {
|
||||||
|
$id = htmlspecialchars($row['identyfikator'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||||
|
$im = htmlspecialchars($row['imie'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||||
|
$na = htmlspecialchars($row['nazwisko'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||||
|
$em = htmlspecialchars($row['email'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||||
|
|
||||||
|
$html .= '<tr>';
|
||||||
|
$html .= '<td>' . $id . '</td>';
|
||||||
|
$html .= '<td>' . $im . '</td>';
|
||||||
|
$html .= '<td>' . $na . '</td>';
|
||||||
|
$html .= '<td>' . $em . '</td>';
|
||||||
|
$html .= '</tr>';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$html .= '<tr><td colspan="4">Brak danych</td></tr>';
|
||||||
|
}
|
||||||
|
|
||||||
|
$html .= '</tbody></table>';
|
||||||
|
|
||||||
|
|
||||||
|
mysqli_commit($db);
|
||||||
|
fclose($f);
|
||||||
|
mysqli_close($db);
|
||||||
|
|
||||||
|
echo <<<HTML
|
||||||
|
|
||||||
|
<!doctype html>
|
||||||
|
<html lang="pl">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport"
|
||||||
|
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||||
|
<title>T61b - pacjenci php z bazą danych i plikiem tekstowym</title>
|
||||||
|
<link rel="stylesheet" href="style.css">
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<header>
|
||||||
|
<h1>Zadanie T61b</h1>
|
||||||
|
<h2>Autor: Jakub Grzegorczyk</h2>
|
||||||
|
</header>
|
||||||
|
<div class="box">
|
||||||
|
<p>
|
||||||
|
1. Utwórz bazę danych o nazwie 3p_1_pacjenci. <br><br>
|
||||||
|
2. W bazie danych utwórz tabelę tabela_1 zawierającą kolumny: <br><br>
|
||||||
|
<ul>
|
||||||
|
<li>identyfikator,</li>
|
||||||
|
<li>imię,</li>
|
||||||
|
<li>nazwisko,</li>
|
||||||
|
<li>email.</li>
|
||||||
|
</ul>
|
||||||
|
3. Utwórz plik tekstowy o nazwie dane.txt zawierający dane 3 pacjentów. <br><br>
|
||||||
|
4. Napisz skrypt php, który czyta dane z pliku i zapisuje je do tabeli tabela_1 i wyświetla je na stronie zadanie.php w postaci tabeli.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="box">
|
||||||
|
{$html}
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
HTML;
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
* {
|
||||||
|
box-sizing: border-box;
|
||||||
|
}
|
||||||
|
body {
|
||||||
|
font-family: Verdana, serif;
|
||||||
|
background: #ffffff;
|
||||||
|
margin: 15px;
|
||||||
|
font-size: 0.9em;
|
||||||
|
}
|
||||||
|
header {
|
||||||
|
border: 2px solid black;
|
||||||
|
border-radius: 1em;
|
||||||
|
padding: 10px 20px;
|
||||||
|
box-shadow: rgba(0, 0, 0, 0.2) 3px 3px 5px;
|
||||||
|
background: #f0f0f0;
|
||||||
|
}
|
||||||
|
|
||||||
|
input {
|
||||||
|
margin-top: 5px;
|
||||||
|
margin-bottom: 5px;
|
||||||
|
width: 30%;
|
||||||
|
border: black 2px solid;
|
||||||
|
border-radius: 0.5em;
|
||||||
|
height: 2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
button {
|
||||||
|
padding: 5px;
|
||||||
|
width: 30%;
|
||||||
|
border: black 2px solid;
|
||||||
|
border-radius: 0.5em;
|
||||||
|
font-weight: bold;
|
||||||
|
margin-top: 10px;
|
||||||
|
}
|
||||||
|
pre {
|
||||||
|
font-family: Verdana, serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.box {
|
||||||
|
border: 2px solid black;
|
||||||
|
padding: 15px 20px;
|
||||||
|
border-radius: 1em;
|
||||||
|
margin: 15px 0 10px 0;
|
||||||
|
box-shadow: rgba(0, 0, 0, 0.2) 3px 3px 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.box h3 {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
td {
|
||||||
|
width: 50px;
|
||||||
|
height: 50px;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
tr {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.y {
|
||||||
|
background: yellow;
|
||||||
|
}
|
||||||
|
|
||||||
|
.b {
|
||||||
|
background:blue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
-- phpMyAdmin SQL Dump
|
||||||
|
-- version 5.2.1
|
||||||
|
-- https://www.phpmyadmin.net/
|
||||||
|
--
|
||||||
|
-- Host: 127.0.0.1
|
||||||
|
-- Generation Time: Paź 09, 2025 at 12:21 PM
|
||||||
|
-- Wersja serwera: 10.4.32-MariaDB
|
||||||
|
-- Wersja PHP: 8.2.12
|
||||||
|
|
||||||
|
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
|
||||||
|
START TRANSACTION;
|
||||||
|
SET time_zone = "+00:00";
|
||||||
|
|
||||||
|
|
||||||
|
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
|
||||||
|
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
|
||||||
|
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
|
||||||
|
/*!40101 SET NAMES utf8mb4 */;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Database: `3p_1_pacjenci`
|
||||||
|
--
|
||||||
|
|
||||||
|
-- --------------------------------------------------------
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Struktura tabeli dla tabeli `tabela_1`
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE TABLE `tabela_1` (
|
||||||
|
`identyfikator` varchar(50) NOT NULL,
|
||||||
|
`imie` varchar(150) NOT NULL,
|
||||||
|
`nazwisko` varchar(150) NOT NULL,
|
||||||
|
`email` varchar(200) NOT NULL
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_polish_ci;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Dumping data for table `tabela_1`
|
||||||
|
--
|
||||||
|
|
||||||
|
INSERT INTO `tabela_1` (`identyfikator`, `imie`, `nazwisko`, `email`) VALUES
|
||||||
|
('1', 'Jan', 'Kowalski', 'jankowalski@example.com'),
|
||||||
|
('2', 'Anna', 'Nowak', 'annanowak@mail.com'),
|
||||||
|
('3', 'Piotr', 'Nowak', 'pnowak@example.pl');
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Indeksy dla zrzutów tabel
|
||||||
|
--
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Indeksy dla tabeli `tabela_1`
|
||||||
|
--
|
||||||
|
ALTER TABLE `tabela_1`
|
||||||
|
ADD PRIMARY KEY (`identyfikator`);
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
|
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
|
||||||
|
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
|
||||||
|
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
|
||||||
Reference in New Issue
Block a user