簡體   English   中英

在按鈕單擊php上顯示新的查詢結果

[英]Display new query results on button click php

我有一個頁面在加載時顯示查詢結果。 還有一個日期范圍選擇器,選擇該日期范圍選擇器時必須運行相同的查詢並顯示更新的結果。 該頁面加載完美,但是當我選擇日期范圍並單擊按鈕時,什么也沒有發生。 這是頁面的代碼和圖像。 我是php和html的新手,通過構建Web應用程序進行學習。 因此,請問如果我的問題很基礎又愚蠢,請原諒。 頁面截圖

 <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">&nbsp;&nbsp;&nbsp;&nbsp; <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];
                ...
            }

?>

您需要<form>標記來發送數據。 喜歡

<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">&nbsp;&nbsp;&nbsp;&nbsp;
            <button type="submit" class="btn btn-success" name="todate" id="todate" style="width: 10%;" value="Date Run" >Go</button>
        </div>
    </div>
</form>

首先設置您的ID唯一。

<button type = "submit" class = "btn btn-success" name = "btnTodate" id = "btnTodate" style = "width: 10%;" value = "Date Run" >Go</button>

像這樣用過的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) {
}})});

您可以在此處顯示的表單中獲取所有設置的數據

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM