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 to only slide trough the years when the publications where 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'];
?>
<script>
// 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;
}
</script>
<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 tought on storing the distinct year values of the query on a array and then pass it to the slider but i don’t know how to do that. Any help would be aprecciated.
xDeMoNaTiOn is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.