我采用了范围 slider 小部件并根据我的需要对其进行了自定义:
$(function () { $inputFrom = $(".js-input-from"),
$inputTo = $(".js-input-to"),
$("#kalorie").ionRangeSlider({
hide_min_max: false,
keyboard: true,
max_postfix: "+",
max: 4000,
min: 500,
from: 2,
to: 5,
type: 'double',
postfix: "kcal",
grid: true,
values: [
"500", "1000", "1250",
"1500", "1750",
"2000", "2250", "2500", "2750", "3000", "3500", "4000" ],
onStart: updateInputs,
onChange: updateInputs,
onFinish: updateInputs
});
});
我现在想要做的是将其中的values[]替换为我从MySQL数据库中提取的内容(例如按ASC排序的10个不同值)
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
$conn->set_charset("utf8");
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql2 = "SELECT DISTINCT * FROM TABLE";
$result2 = $conn->query($sql2);
if ($result2->num_rows > 0) {
// output data of each row
while($row2 = $result2->fetch_assoc()) {
如何将输出保存到变量中,以便可以将其链接到 slider 代码中?
最佳答案
从数据库中一条一条地获取记录并将所有记录存储在一个数组中:
while($row2 = $result2->fetch_assoc()) {
$all_values[] = $row2['column_name']; // store all records in one array
}
$final_values = implode(",",$all_values);
然后将 $final_valuse变量放入
javascript`代码
$("#kalorie").ionRangeSlider({
hide_min_max: false,
keyboard: true,
max_postfix: "+",
max: 4000,
min: 500,
from: 2,
to: 5,
type: 'double',
postfix: "kcal",
grid: true,
values: [<?php echo $final_values; ?>], // echo your PHP variable here
onStart: updateInputs,
onChange: updateInputs,
onFinish: updateInputs
});
关于php - MySQL 数据库中的范围 slider 和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35100042/