[英]Display new query results on button click php
I have a page that displays a query result on load. 我有一个页面在加载时显示查询结果。 there is also a date range selector, which when selected has to run the same query and display the updated results.
还有一个日期范围选择器,选择该日期范围选择器时必须运行相同的查询并显示更新的结果。 The page loads perfectly, but when i select the date range and click the button, nothing happens.
该页面加载完美,但是当我选择日期范围并单击按钮时,什么也没有发生。 Here is the code and the image of the page.
这是页面的代码和图像。 I am a newbie in php and html, learning by building a web application.
我是php和html的新手,通过构建Web应用程序进行学习。 So please excuse if my question is very basic and dumb.
因此,请问如果我的问题很基础又愚蠢,请原谅。 Screenshot of Page
页面截图
<html> <body> <div class="container"> <h1>Welcome <?php echo $login_session; ?></h1><br></br> <div class="row"> <div class="panel panel-black"> <div class="panel-heading form-inline"> <div class="row"> <div class="col-md-8"> <label class="control-label" for="fromdate">From:</label> <input type="date" class="form-control" id="fromdate" name="fromdate"> <label class="control-label" for="todate">To:</label> <input type="date" class="form-control" id="todate" name="todate"> <button type="submit" class="btn btn-success" name="todate" id="todate" style="width: 10%;" value="Date Run" >Go</button> </div> </div> </div> </div> </div> <div class="row"> <div class="col-lg-3 col-md-6"> <div class="panel panel-blue"> <div class="panel-heading"> <div class="row"> <div class="col-xs-9 text-justify"> <div class="huge"><strong><?php echo $main_total_pledges; ?></strong></div> <div>Total Pledges</div> </div> .... </div> </div> </div> </div> </div> </body> </html>
<?php
include('session.php');
if(isset($_POST["todate"])=="Date Run")
{
$main_query = mysqli_query($db,"SELECT count(a.pledge_id) total_pledges, sum(case when processed_status = 'Approved' then 1 else 0 end) approved, sum(case when processed_status = 'Cancelled' then 1 else 0 end) Cancelled, sum(case when processed_status in ('Alien','Single Gift') then 1 else 0 end) Gift, sum(case when processed_status is null then 1 else 0 end) Pending from waysact_source a left join vlc_processed_item b on a.pledge_id = b.pledge_id where a.fundraiser in (select distinct concat(f_firstname,' ',f_lastname) fundraiser from fundraiser where f_company in (select contractor_name from contractor where company_name = '$_SESSION[login_user]')) and a.pledge_date = '2017-06-06'");
$main_query_result = mysqli_fetch_row($main_query);
$main_total_pledges = $main_query_result[0];
...
} else
{
$main_query = mysqli_query($db,"SELECT count(a.pledge_id) total_pledges, sum(case when processed_status = 'Approved' then 1 else 0 end) approved, sum(case when processed_status = 'Cancelled' then 1 else 0 end) Cancelled, sum(case when processed_status in ('Alien','Single Gift') then 1 else 0 end) Gift, sum(case when processed_status is null then 1 else 0 end) Pending from waysact_source a left join vlc_processed_item b on a.pledge_id = b.pledge_id where a.fundraiser in (select distinct concat(f_firstname,' ',f_lastname) fundraiser from fundraiser where f_company in (select contractor_name from contractor where company_name = '$_SESSION[login_user]'))");
$main_query_result = mysqli_fetch_row($main_query);
$main_total_pledges = $main_query_result[0];
...
}
?>
You need <form>
tag to send data. 您需要
<form>
标记来发送数据。 Like 喜欢
<form action="" method="">
<div class="row">
<div class="col-md-8">
<label class="control-label" for="fromdate">From:</label>
<input type="date" class="form-control" id="fromdate" name="fromdate">
<label class="control-label" for="todate">To:</label>
<input type="date" class="form-control" id="todate" name="todate">
<button type="submit" class="btn btn-success" name="todate" id="todate" style="width: 10%;" value="Date Run" >Go</button>
</div>
</div>
</form>
First set Your id unique. 首先设置您的ID唯一。
<button type = "submit" class = "btn btn-success" name = "btnTodate" id = "btnTodate" style = "width: 10%;" value = "Date Run" >Go</button>
And Used Ajax like that 像这样用过的Ajax
$(document).on('click', 'btnTodate', function(){
var dataValue = {setQuery: 1, data: $("#form_ID").serialize()}
$.ajax({
url: 'YOUR_PHP_FILE',
dataType: "json",
data: dataValue, success: function (r) {
}})});
And You can get all kind of data that you set in your form display here 您可以在此处显示的表单中获取所有设置的数据
YOUR_PHP_FILE.php YOUR_PHP_FILE.php
if (isset($_REQUEST['setQuery'])) {
$dataAuto = array();
parse_str($_POST['data'], $dataAuto);
if (!empty($dataAuto["todate"])) {
$main_query = mysqli_query($db, "SELECT count(a.pledge_id) total_pledges, sum(case when processed_status = 'Approved' then 1 else 0 end) approved, sum(case when processed_status = 'Cancelled' then 1 else 0 end) Cancelled, sum(case when processed_status in ('Alien','Single Gift') then 1 else 0 end) Gift, sum(case when processed_status is null then 1 else 0 end) Pending from waysact_source a left join vlc_processed_item b on a.pledge_id = b.pledge_id where a.fundraiser in (select distinct concat(f_firstname,' ',f_lastname) fundraiser from fundraiser where f_company in (select contractor_name from contractor where company_name = '{$_SESSION['login_user']}')) and a.pledge_date = '2017-06-06'");
$main_query_result = mysqli_fetch_row($main_query);
$main_total_pledges = $main_query_result[0];
} else {
$main_query = mysqli_query($db, "SELECT count(a.pledge_id) total_pledges, sum(case when processed_status = 'Approved' then 1 else 0 end) approved, sum(case when processed_status = 'Cancelled' then 1 else 0 end) Cancelled, sum(case when processed_status in ('Alien','Single Gift') then 1 else 0 end) Gift, sum(case when processed_status is null then 1 else 0 end) Pending from waysact_source a left join vlc_processed_item b on a.pledge_id = b.pledge_id where a.fundraiser in (select distinct concat(f_firstname,' ',f_lastname) fundraiser from fundraiser where f_company in (select contractor_name from contractor where company_name = '{$_SESSION['login_user']}'))");
$main_query_result = mysqli_fetch_row($main_query);
$main_total_pledges = $main_query_result[0];
}
die;}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.