reload data from db badly needed
This commit is contained in:
u1 2024-11-14 14:36:23 +01:00
parent 2fbf0bb91d
commit 616a1e2e68
5 changed files with 49 additions and 125 deletions

37
@
View File

@ -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 = '';
}
});
*/
});

View File

@ -6,7 +6,8 @@
<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/script.js"></script> <script type="module" src="js/get.js"></script>
<script type="module" src="js/post.js"></script>
</head> </head>
<body> <body>
@ -43,6 +44,16 @@
</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>

View File

@ -1,35 +1,42 @@
const fuelType = document.getElementById('fuel-type');
const cena = document.getElementById("cena");
let usersData = [];
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
const imieSelect = document.getElementById('imie'); fetch('php/get.php')
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(dane => { data.forEach(row => {
const option = document.createElement('option'); const option = document.createElement('option');
option.value = dane.id; option.value = row["nazwa"];
option.textContent = dane.imie + " " + dane.nazwisko; option.textContent = row["nazwa"];
imieSelect.appendChild(option); fuelType.appendChild(option);
});
}) console.log(row);
.catch(error => console.error('Error fetching data:', error));
}); });
imieSelect.addEventListener('change', function() { console.log(data);
const selectedId = imieSelect.value; })
const selectedPerson = usersData.find(dane => dane.id == selectedId); .catch(error => console.error('Error fetching data:', error));
if (selectedPerson && selectedPerson.photo) {
photoDisplay.src = 'data:image/jpeg;base64,' + selectedPerson.photo;
} else {
photoDisplay.src = '';
}
});
}); });
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");
}
});

View File

@ -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");
}
});

View File

@ -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);
?>