So i am working on a site on php and i have to do a slider for the years of publications. Explaining in more detail, what i want is only to slide through the years when the publications were made.
// Your database connection and other PHP code
// Query to retrieve the minimum and maximum publication years
$query = "SELECT MIN(YEAR(data)) AS min_year, MAX(YEAR(data)) AS max_year FROM publicacoes";
$stmt = $pdo->prepare($query);
$stmt->execute();
$result = $stmt->fetch(PDO::FETCH_ASSOC);
// Retrieve the minimum and maximum years from the query result
$minYear = $result['min_year'];
$maxYear = $result['max_year'];
// JavaScript function to update the displayed value when slider changes
function updateSliderValue() {
var slider = document.getElementById("yearSlider");
var selectedYearDisplay = document.getElementById("selectedYearDisplay");
// Update the displayed value
selectedYearDisplay.innerText = slider.value;
}
<input id="yearSlider" type="range"
min="<?= $minYear ?>" max="<?= $maxYear ?>"
value="<?= $maxYear ?>" onchange="updateSliderValue()">
<span id="selectedYearDisplay"></span>
This code only limit the slider from the first year that a publication were made until the most recent publication year.
The years are in the column "data" of the publications table.
I thought about storing the distinct year values in an array and then passing it to the slider but i don't know how to do that. Any help would be appreciated.