Compare commits
No commits in common. "2d1185ff074c75125d7904d5a91b70a1ef71ee32" and "2fbf0bb91d77589f0cd4556cd95e6e220643f636" have entirely different histories.
2d1185ff07
...
2fbf0bb91d
|
@ -0,0 +1,37 @@
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
|
||||||
|
//const imieSelect = document.getElementById('imie');
|
||||||
|
|
||||||
|
let usersData = [];
|
||||||
|
|
||||||
|
imieSelect.addEventListener('focus', function() {
|
||||||
|
fetch('php/gget.php')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
/*
|
||||||
|
usersData = data;
|
||||||
|
imieSelect.innerHTML = "";
|
||||||
|
data.forEach(dane => {
|
||||||
|
const option = document.createElement('option');
|
||||||
|
option.value = dane.id;
|
||||||
|
option.textContent = dane.imie + " " + dane.nazwisko;
|
||||||
|
imieSelect.appendChild(option);
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
|
||||||
|
console.log(data);
|
||||||
|
})
|
||||||
|
.catch(error => console.error('Error fetching data:', error));
|
||||||
|
});
|
||||||
|
/*
|
||||||
|
imieSelect.addEventListener('change', function() {
|
||||||
|
const selectedId = imieSelect.value;
|
||||||
|
const selectedPerson = usersData.find(dane => dane.id == selectedId);
|
||||||
|
if (selectedPerson && selectedPerson.photo) {
|
||||||
|
photoDisplay.src = 'data:image/jpeg;base64,' + selectedPerson.photo;
|
||||||
|
} else {
|
||||||
|
photoDisplay.src = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
*/
|
||||||
|
});
|
13
index.html
13
index.html
|
@ -6,8 +6,7 @@
|
||||||
<title>Całodobowa stacja paliw</title>
|
<title>Całodobowa stacja paliw</title>
|
||||||
<link rel="stylesheet" href="css/style.css">
|
<link rel="stylesheet" href="css/style.css">
|
||||||
|
|
||||||
<script type="module" src="js/get.js"></script>
|
<script type="module" src="js/script.js"></script>
|
||||||
<script type="module" src="js/post.js"></script>
|
|
||||||
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -44,16 +43,6 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<h2>Orientacyjny koszt paliwa</h2>
|
|
||||||
|
|
||||||
<input type="text" id="fuel" name="name">
|
|
||||||
<input type="text" id="price" name="price">
|
|
||||||
<button type="button" id="btn">Oblicz</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="footer">
|
<div class="footer">
|
||||||
Stronę opracował: 000000000000
|
Stronę opracował: 000000000000
|
||||||
</div>
|
</div>
|
||||||
|
|
53
js/get.js
53
js/get.js
|
@ -1,42 +1,35 @@
|
||||||
const fuelType = document.getElementById('fuel-type');
|
|
||||||
|
|
||||||
const cena = document.getElementById("cena");
|
|
||||||
|
|
||||||
let usersData = [];
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', function() {
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
fetch('php/get.php')
|
const imieSelect = document.getElementById('imie');
|
||||||
|
const photoDisplay = document.createElement('img');
|
||||||
|
photoDisplay.style.width = "200px";
|
||||||
|
photoDisplay.style.height = "auto";
|
||||||
|
document.getElementById('prawy').appendChild(photoDisplay);
|
||||||
|
|
||||||
|
let usersData = [];
|
||||||
|
|
||||||
|
imieSelect.addEventListener('focus', function() {
|
||||||
|
fetch('get.php')
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
usersData = data;
|
usersData = data;
|
||||||
|
imieSelect.innerHTML = "";
|
||||||
data.forEach(row => {
|
data.forEach(dane => {
|
||||||
const option = document.createElement('option');
|
const option = document.createElement('option');
|
||||||
option.value = row["nazwa"];
|
option.value = dane.id;
|
||||||
option.textContent = row["nazwa"];
|
option.textContent = dane.imie + " " + dane.nazwisko;
|
||||||
fuelType.appendChild(option);
|
imieSelect.appendChild(option);
|
||||||
|
|
||||||
console.log(row);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log(data);
|
|
||||||
})
|
})
|
||||||
.catch(error => console.error('Error fetching data:', error));
|
.catch(error => console.error('Error fetching data:', error));
|
||||||
});
|
});
|
||||||
|
|
||||||
fuelType.addEventListener('change', function() {
|
imieSelect.addEventListener('change', function() {
|
||||||
console.log("Zmiana wybranego paliwa");
|
const selectedId = imieSelect.value;
|
||||||
const selectedId = fuelType.value;
|
const selectedPerson = usersData.find(dane => dane.id == selectedId);
|
||||||
|
if (selectedPerson && selectedPerson.photo) {
|
||||||
const selectedFuel = usersData.find(dane => dane.nazwa === selectedId);
|
photoDisplay.src = 'data:image/jpeg;base64,' + selectedPerson.photo;
|
||||||
|
|
||||||
cena.textContent = selectedFuel["cena"];
|
|
||||||
console.log("mati");
|
|
||||||
if (selectedFuel) {
|
|
||||||
const cena = selectedFuel.cena;
|
|
||||||
console.log("Cena wybranego paliwa:", cena);
|
|
||||||
} else {
|
} else {
|
||||||
console.error("Nie znaleziono ceny dla wybranego paliwa");
|
photoDisplay.src = '';
|
||||||
}
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
36
js/post.js
36
js/post.js
|
@ -1,36 +0,0 @@
|
||||||
document.getElementById('btn').addEventListener('click', async () => {
|
|
||||||
|
|
||||||
const fuelType = document.getElementById('fuel').value;
|
|
||||||
const liters = document.getElementById('price').value;
|
|
||||||
|
|
||||||
// Spakuj dane w formacie JSON
|
|
||||||
const data = {
|
|
||||||
nazwa: fuelType,
|
|
||||||
cena: parseFloat(liters) // konwertuj na liczbę, jeśli wartość jest liczbową
|
|
||||||
};
|
|
||||||
|
|
||||||
console.log("ok");
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Wykonaj żądanie POST
|
|
||||||
const response = await fetch('php/post.php', {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify(data)
|
|
||||||
});
|
|
||||||
|
|
||||||
// Przetwarzanie odpowiedzi
|
|
||||||
if (response.ok) {
|
|
||||||
const result = await response.json();
|
|
||||||
console.log('Odpowiedź serwera:', result);
|
|
||||||
alert(`Koszt paliwa: ${result.cost}`);
|
|
||||||
} else {
|
|
||||||
console.error('Błąd:', response.statusText);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Błąd:', error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
const fuelType = document.getElementById('fuel-type');
|
||||||
|
|
||||||
|
const cena = document.getElementById("cena");
|
||||||
|
|
||||||
|
let usersData = [];
|
||||||
|
|
||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
fetch('php/gget.php')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
usersData = data;
|
||||||
|
|
||||||
|
data.forEach(row => {
|
||||||
|
const option = document.createElement('option');
|
||||||
|
option.value = row["nazwa"];
|
||||||
|
option.textContent = row["nazwa"];
|
||||||
|
fuelType.appendChild(option);
|
||||||
|
|
||||||
|
console.log(row);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(data);
|
||||||
|
})
|
||||||
|
.catch(error => console.error('Error fetching data:', error));
|
||||||
|
});
|
||||||
|
|
||||||
|
fuelType.addEventListener('change', function() {
|
||||||
|
console.log("Zmiana wybranego paliwa");
|
||||||
|
const selectedId = fuelType.value;
|
||||||
|
|
||||||
|
const selectedFuel = usersData.find(dane => dane.nazwa === selectedId);
|
||||||
|
|
||||||
|
cena.textContent = selectedFuel["cena"];
|
||||||
|
console.log("mati");
|
||||||
|
if (selectedFuel) {
|
||||||
|
const cena = selectedFuel.cena;
|
||||||
|
console.log("Cena wybranego paliwa:", cena);
|
||||||
|
} else {
|
||||||
|
console.error("Nie znaleziono ceny dla wybranego paliwa");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
$polaczenie = mysqli_connect("172.18.0.3", "root", "secret", "db");
|
$polaczenie = mysqli_connect("172.19.0.2", "root", "secret", "db");
|
||||||
|
|
||||||
$kwerenda = mysqli_query($polaczenie, "SELECT * FROM paliwa ORDER BY id DESC LIMIT 3;");
|
$kwerenda = mysqli_query($polaczenie, "SELECT * FROM paliwa ORDER BY id DESC LIMIT 3;");
|
||||||
|
|
20
php/post.php
20
php/post.php
|
@ -1,20 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
$dbhost = "172.18.0.3";
|
|
||||||
$dbuser = "root";
|
|
||||||
$dbpass = "secret";
|
|
||||||
$dbname = "db";
|
|
||||||
|
|
||||||
$con = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
|
|
||||||
|
|
||||||
$rawData = file_get_contents('php://input');
|
|
||||||
|
|
||||||
$data = json_decode($rawData, true);
|
|
||||||
|
|
||||||
$kw = "INSERT INTO paliwa (nazwa, cena) VALUES ('{$data['nazwa']}', {$data['cena']} );";
|
|
||||||
|
|
||||||
echo json_encode($kw);
|
|
||||||
|
|
||||||
$ans = mysqli_query($con, $kw);
|
|
||||||
|
|
||||||
?>
|
|
|
@ -1,4 +0,0 @@
|
||||||
curl -X POST http://localhost:8080/p14.11/php/post.php \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d '{"nazwa": "Diesel", "cena": 5.25}'
|
|
||||||
|
|
Loading…
Reference in New Issue