diff --git a/i1.html b/i1.html
index 7047556..5721596 100644
--- a/i1.html
+++ b/i1.html
@@ -4,6 +4,8 @@
Kursy komputerowe
+
+
@@ -17,7 +19,7 @@
Kursy komputerowe - programowanie
-
+
| Kurs |
Czas trwania |
diff --git a/js/script.js b/js/script.js
index c253f06..cdccd18 100644
--- a/js/script.js
+++ b/js/script.js
@@ -1,37 +1,44 @@
document.addEventListener('DOMContentLoaded', function() {
- document.getElementById('oblicz').addEventListener('click', function() {
- // Pobieranie wybranych kursów
- const wybraneKursy = document.querySelectorAll('input[name="kurs"]:checked');
- // Ceny kursów
- const cenaReact = 1500;
- const cenaJavaScript = 1200;
-
- // Obliczanie całkowitej kwoty
- let calkowitaKwota = 0;
- wybraneKursy.forEach(kurs => {
- if (kurs.value === 'React.js') {
- calkowitaKwota += cenaReact;
- } else if (kurs.value === 'JavaScript') {
- calkowitaKwota += cenaJavaScript;
- }
- });
-
- // Pobieranie liczby rat
- const iloscRat = parseInt(document.getElementById('raty').value);
- // Pobieranie miasta
- const miasto = document.getElementById('miasto').value;
-
- // Sprawdzanie poprawności danych
- if (wybraneKursy.length === 0 || isNaN(iloscRat) || iloscRat <= 0) {
- document.getElementById('wynik').textContent = 'Proszę wybrać przynajmniej jeden kurs i podać poprawną liczbę rat.';
- return;
+ console.log("ok");
+
+ const fetchData = () => {
+ return fetch('./php/get.php')
+ .then(response => {
+ if (!response.ok) {
+ throw new Error('Błąd pobierania danych');
+ }
+ return response.json();
+ })
+ .then(data => {
+ console.log("Dane załadowane:", data);
+ renderTable(data); // Wywołaj funkcję renderującą tabelę
+ })
+ .catch(error => {
+ console.error("Błąd:", error);
+ });
+ };
+
+ // Funkcja do renderowania danych w tabeli
+ const renderTable = (data) => {
+ const table = document.getElementById('tab');
+
+ // Usuń wszystkie rzędy po nagłówku (czyli od drugiego)
+ while (table.rows.length > 1) {
+ table.deleteRow(1);
}
-
- // Obliczanie miesięcznej raty
- const rata = calkowitaKwota / iloscRat;
-
- // Wyświetlanie wyniku
- document.getElementById('wynik').textContent =
- `Kurs odbędzie się w ${miasto}. Koszt całkowity: ${calkowitaKwota} zł. Płacisz ${iloscRat} rat po ${rata.toFixed(2)} zł`;
- });
+
+ // Dodaj nowe wiersze dla każdego kursu
+ data.forEach(row => {
+ const tr = document.createElement('tr');
+ tr.innerHTML = `
+ ${row.kurs} |
+ ${row.czas_trwania} |
+ ${row.cena} |
+ `;
+ table.appendChild(tr);
+ });
+ };
+
+ // Uruchom pobieranie danych
+ fetchData();
});