我正在开发一个总结报告摘要的页面。默认情况下,它仅显示今天。我用这个:
include $koneksi
$date ='current_date';
$query1 = mysqli_query($koneksi,"SELECT * from daftar where tanggal=subdate($date, 1)");
$result=mysqli_num_rows($query1);
这是我的HTML
<div class="count blue"><?php echo $result." people(s)"?></div>
并且它有效,查询的结果是我所期望的。
现在我需要使用datepicker更改$ date变量的值。
<div class='input-group date' id='myDatepicker'>
<input type='text' class="form-control" />
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
我想要它,以便每次我点击datepicker时,变量$ date都会改变,页面将自动重新加载(相同页面但不同的查询结果)。
如果您希望数据显示在同一页面中,则可以更好地使用Angular。这里,为了显示我使用angularJs的流程,但是对angularJs的支持已经停止,所以根据需要使用Angular或reactJs(搜索更多关于它)
使用html构造一个表单并使用angularJs http.post(),将表单数据发布到php
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
<script>
$(document).ready(function(){
var date_input=$('input[name="inpDate"]'); //our date input has the name "date"
var container=$('.bootstrap-iso form').length>0 ? $('.bootstrap-iso form').parent() : "body";
var options={
format: 'yyyy-mm-dd',
container: container,
todayHighlight: true,
autoclose: true,
};
date_input.datepicker(options);
});
</script>
<form ng-submit="submit()">
<label>Date</label>
<input class="form-control" ng-model="inpDate" id="date" name="inpDate" placeholder="YYYY-MM-DD" type="text" required="required"/>
</form>
并编写一个单独的angularJs文件,如下所示。提交时,这将发送日期到PHP文件并获得响应。
$scope.submit = function(){
var date1=$scope.inpDate;
$http.get('http://localhost/report/urfile.php?inpdate='+date1).success(function(shiftdata) {
$scope.dbValue = shiftdata;
console.log(JSON.stringify(shiftdata) );
});
}
在此之后修改您的php将接收数据并相应地发送响应。
现在数据是URL,您可以在下面的ph中获取它。 urfile.php
$date = $_GET['inpdate'];