当我在 Bootstrap 日期范围选择器中更改日期时,更改的日期不会触发
Changed date is not fire when I am changing it in Bootstrap Date Range Picker
在下面的代码中,我想更新 from 和 to[=26 中的输入选定日期(通过 Bootstrap 日期范围选择器) =] cashadvance 查询中使用的变量。
我认为他们是日期范围选择器回调函数中的问题。
两个变量 range_to 和 range_from 值在带有 id=reservation 的输入标签中获取,然后使用 isset($_GET[range])
从和到中获取它们的值,但它不起作用。
代码:payrol.php
<?php
include('db.php');
$range_to = date('m/d/Y');
$range_from = date('m/d/Y', strtotime('-30 day', strtotime($range_to)));
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container-fluid">
<div class="box-header with-border">
<div class="pull-left">
<input type="text" class="form-control pull-right col-sm-13" id="reservation" name="date_range" value="<?php echo (isset($_GET['range'])) ? $_GET['range'] : $range_from.' - '.$range_to; ?>">
</div>
</div>
<table>
<thead>
<tr>
<th>Employee ID</th>
<th>Gross</th>
<th>Cash Advance</th>
<th>Range</th>
</tr>
</thead>
<?php
$to = date('Y-m-d');
$from = date('Y-m-d', strtotime('-30 day', strtotime($to)));
if(isset($_GET['range'])){
$range = $_GET['range'];
$ex = explode(' - ', $range);
$from = date('Y-m-d', strtotime($ex[0]));
$to = date('Y-m-d', strtotime($ex[1]));
}
/* **********Fetch Record From Employee ************ */
$sql = "SELECT * from employee";
$query = $con->query($sql);
$total = 0;
while($row = $query->fetch_assoc()){
$empid = $row['id'];
/* ********* Cash Advance Query********* */
$casql = "SELECT *, SUM(aamount) AS cashamount FROM advance WHERE id='$empid' AND adate BETWEEN '$from' AND '$to'";
$caquery = $con->query($casql);
$carow = $caquery->fetch_assoc();
$cashadvance = $carow['cashamount'];
$gross = $row['Salary'] ;
echo "
<tr>
<td>".$row['empid']."</td>
<td>".number_format($gross, 2)."</td>
<td>".number_format($cashadvance, 2)."</td>
<td>".$from."-".$to. "</td>
</tr>
";
}
?>
</table>
</div>
<script>
$(function(){
$("#reservation").on('change', function(){
var range = encodeURI($(this).val());
window.location = 'payrol.php?range='+range;
});
});
</script>
<!--************Date Range Picker********************-->
<script>
$(function() {
//Date range picker
$('#reservation').daterangepicker()
$('input[name="date_range"]').daterangepicker({
opens: 'left'
}, function(start, end, label) {
console.log("A new date selection was made: " + start.format('YYYY-MM-DD') + ' - ' + end.format('YYYY-MM-DD'));
});
});
</script>
</body>
</html>
在浏览器中检查对象是否绑定了事件。如果没有,您可能需要在绑定之前等待文档准备就绪:
$(document).ready(function(){
$("#reservation").on('change', function(){
var range = encodeURI($(this).val());
window.location = 'payrol.php?range='+range;
});
});
在下面的代码中,我想更新 from 和 to[=26 中的输入选定日期(通过 Bootstrap 日期范围选择器) =] cashadvance 查询中使用的变量。 我认为他们是日期范围选择器回调函数中的问题。
两个变量 range_to 和 range_from 值在带有 id=reservation 的输入标签中获取,然后使用 isset($_GET[range])
从和到中获取它们的值,但它不起作用。
代码:payrol.php
<?php
include('db.php');
$range_to = date('m/d/Y');
$range_from = date('m/d/Y', strtotime('-30 day', strtotime($range_to)));
?>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container-fluid">
<div class="box-header with-border">
<div class="pull-left">
<input type="text" class="form-control pull-right col-sm-13" id="reservation" name="date_range" value="<?php echo (isset($_GET['range'])) ? $_GET['range'] : $range_from.' - '.$range_to; ?>">
</div>
</div>
<table>
<thead>
<tr>
<th>Employee ID</th>
<th>Gross</th>
<th>Cash Advance</th>
<th>Range</th>
</tr>
</thead>
<?php
$to = date('Y-m-d');
$from = date('Y-m-d', strtotime('-30 day', strtotime($to)));
if(isset($_GET['range'])){
$range = $_GET['range'];
$ex = explode(' - ', $range);
$from = date('Y-m-d', strtotime($ex[0]));
$to = date('Y-m-d', strtotime($ex[1]));
}
/* **********Fetch Record From Employee ************ */
$sql = "SELECT * from employee";
$query = $con->query($sql);
$total = 0;
while($row = $query->fetch_assoc()){
$empid = $row['id'];
/* ********* Cash Advance Query********* */
$casql = "SELECT *, SUM(aamount) AS cashamount FROM advance WHERE id='$empid' AND adate BETWEEN '$from' AND '$to'";
$caquery = $con->query($casql);
$carow = $caquery->fetch_assoc();
$cashadvance = $carow['cashamount'];
$gross = $row['Salary'] ;
echo "
<tr>
<td>".$row['empid']."</td>
<td>".number_format($gross, 2)."</td>
<td>".number_format($cashadvance, 2)."</td>
<td>".$from."-".$to. "</td>
</tr>
";
}
?>
</table>
</div>
<script>
$(function(){
$("#reservation").on('change', function(){
var range = encodeURI($(this).val());
window.location = 'payrol.php?range='+range;
});
});
</script>
<!--************Date Range Picker********************-->
<script>
$(function() {
//Date range picker
$('#reservation').daterangepicker()
$('input[name="date_range"]').daterangepicker({
opens: 'left'
}, function(start, end, label) {
console.log("A new date selection was made: " + start.format('YYYY-MM-DD') + ' - ' + end.format('YYYY-MM-DD'));
});
});
</script>
</body>
</html>
在浏览器中检查对象是否绑定了事件。如果没有,您可能需要在绑定之前等待文档准备就绪:
$(document).ready(function(){
$("#reservation").on('change', function(){
var range = encodeURI($(this).val());
window.location = 'payrol.php?range='+range;
});
});