parent
2fbf0bb91d
commit
616a1e2e68
37
@
37
@
|
@ -1,37 +0,0 @@
|
|||
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,7 +6,8 @@
|
|||
<title>Całodobowa stacja paliw</title>
|
||||
<link rel="stylesheet" href="css/style.css">
|
||||
|
||||
<script type="module" src="js/script.js"></script>
|
||||
<script type="module" src="js/get.js"></script>
|
||||
<script type="module" src="js/post.js"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
|
@ -43,6 +44,16 @@
|
|||
</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">
|
||||
Stronę opracował: 000000000000
|
||||
</div>
|
||||
|
|
61
js/get.js
61
js/get.js
|
@ -1,35 +1,42 @@
|
|||
const fuelType = document.getElementById('fuel-type');
|
||||
|
||||
const cena = document.getElementById("cena");
|
||||
|
||||
let usersData = [];
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
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')
|
||||
fetch('php/get.php')
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
usersData = data;
|
||||
imieSelect.innerHTML = "";
|
||||
data.forEach(dane => {
|
||||
|
||||
data.forEach(row => {
|
||||
const option = document.createElement('option');
|
||||
option.value = dane.id;
|
||||
option.textContent = dane.imie + " " + dane.nazwisko;
|
||||
imieSelect.appendChild(option);
|
||||
});
|
||||
})
|
||||
.catch(error => console.error('Error fetching data:', error));
|
||||
option.value = row["nazwa"];
|
||||
option.textContent = row["nazwa"];
|
||||
fuelType.appendChild(option);
|
||||
|
||||
console.log(row);
|
||||
});
|
||||
|
||||
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 = '';
|
||||
}
|
||||
});
|
||||
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");
|
||||
}
|
||||
});
|
||||
|
||||
|
|
42
js/script.js
42
js/script.js
|
@ -1,42 +0,0 @@
|
|||
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");
|
||||
}
|
||||
});
|
||||
|
15
php/gget.php
15
php/gget.php
|
@ -1,15 +0,0 @@
|
|||
<?php
|
||||
|
||||
$polaczenie = mysqli_connect("172.19.0.2", "root", "secret", "db");
|
||||
|
||||
$kwerenda = mysqli_query($polaczenie, "SELECT * FROM paliwa ORDER BY id DESC LIMIT 3;");
|
||||
|
||||
$json = array();
|
||||
|
||||
while($row = mysqli_fetch_assoc($kwerenda)) {
|
||||
$json [] = $row;
|
||||
};
|
||||
|
||||
echo json_encode($json);
|
||||
|
||||
?>
|
Loading…
Reference in New Issue