报告的日期范围,因查询而无法正常工作

时间:2018-04-04 05:55:29

标签: php jquery jquery-ui

在我的查询中添加哪些内容以限制用户选择错误的日期,

E.G。从3月7日到3月2日,3月2日至7日的交易没有显示,但是当你将它改为3月7日到4月7日它显示所有交易时,是 有什么我可以添加来限制用户这样做。

请帮帮我。

非常感谢。

这是我的sales.php文件,用户将选择要显示的日期。

 <form action="total_sales.php" method="post">
  From: <input type="text" class="datepicker" placeholder="E.G.(2018-01-14)" name="dayfrom" required pattern="[0-9]{4}+[0-9]+[0-9]"> To: <input type="text" class="datepicker" placeholder="E.G.(2018-02-11)" name="dayto" required pattern="[0-9]{4}+[0-9]+[0-9]">
  <input type="submit" value="Show Sales" name="salesbtn" ></form></center>

这是我的total_sales.php文件。

   <head>
<script>
  $(function() {
    $( "#tabs" ).tabs();
  $('a[rel*=facebox]').facebox();
  $( ".datepicker" ).datepicker();
  });

  $(document).ready(function(){
  // Write on keyup event of keyword input element
  $("#searchme").keyup(function(){
    // When value of the input is not blank
    if( $(this).val() != "")
    {
      // Show only matching TR, hide rest of them
      $("#searchTbl tbody>tr").hide();
      $("#searchTbl td:contains-ci('" + $(this).val() + "')").parent("tr").show();
    }
    else
    {
      // When there is no input or clean again, show everything back
      $("#searchTbl tbody>tr").show();
    }
  });
});
// jQuery expression for case-insensitive filter
$.extend($.expr[":"], 
{
    "contains-ci": function(elem, i, match, array) 
  {
    return (elem.textContent || elem.innerText || $(elem).text() || "").toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0;
  }
});
</script>
<script>
function goBack() {
    window.history.back();
}
</script>


<?php include('session.php'); ?>
<?php include('header.php'); ?>
<?php include('navbar.php'); ?>
<style>
.footer1 {
    position: absolute;
    right: 45%;
    font-family: ""Lucida Console", Monaco, monospace";
    top: 0%;
    width: 80%;
    background-color:#F8F8FF;
    color: black;
    text-align: left;
}

h3{
  font-size:20px;
    font-family: "Arial";

}

table {
    width:60%;
}
table, th, td {
    border: 1px solid black;
    border-collapse: collapse;
}
th, td {
    padding: 5px;
    text-align: center;
}
@media print {
  @page { margin: 0; }
  body { margin: 1cm; }

  #printPageButton {
    display: none;
  }
  #e{
    display:none;
  }
  .footer {
    position: fixed;
    left: 0;
    font-family: ""Lucida Console", Monaco, monospace";
    bottom: 0;
    width: 100%;
    background-color:#F8F8FF;
    color: black;
    text-align: center;
}
}
</style>


<div style="height:30px;"></div>
<div id="page-wrapper">

  <div class="row">
        <div class="col-lg-0">


<br><img src="../upload/logo.jpg"  align="center" class="footer1" style="height:50px; width:50px;"><br>

<br>



<?php
if(isset($_POST['salesbtn'])) {
$from = date('Y-m-d', strtotime($_POST['dayfrom']))." 00:00:01";
$to = date('Y-m-d', strtotime($_POST['dayto']))." 23:59:59";
?>
<center><h1> Product Sales Report </h1><h3>From (<?php echo $from; ?>) To (<?php echo $to; ?>)</h3>

  <button id="printPageButton"  onClick="window.print();" class="btn btn-primary" button type="submit">Print</button>

<button id="e" class="btn btn-primary" onclick="goBack()">Back</button> 
<br><br>
<table width="100%" cellspacing="0" cellpadding="0" style="font-family:Arial Narrow, Arial,sans-serif; font-size:15px;" border="1">
      <tr>
        <td width="30%"><div align="center"><strong>Purchase Date</strong></div></td>
        <td width="30%"><div align="center"><strong>Customer</strong></div></td>
        <td width="40%"><div align="center"><strong> Purchase Name</strong></div></td>
        <td width="40%"><div align="center"><strong>Quantity</strong></div></td>
      </tr>
     <?php


try {
require ("conn.php");


$stmt1 = $conn->prepare("select * from sales_detail left join product on product.productid=sales_detail.productid left join sales on sales.salesid=sales_detail.salesid left join customer on sales.userid=customer.userid where product.supplierid='".$_SESSION['id'] ."' AND sales_date BETWEEN '$from' AND '$to' order by sales.sales_date desc");
$stmt1->execute();

while($row=$stmt1->fetch(PDO::FETCH_ASSOC)) {
$sales_date = $row['sales_date'];
$customer_name = $row['customer_name'];
$product_name = $row['product_name'];
$sales_qty = $row['sales_qty'];
?>



<tr align="center">
    <td><?php echo $sales_date; ?></td>
        <td><?php echo $customer_name; ?></td>
    <td><?php echo $product_name; ?></td>
 <td><?php echo $sales_qty; ?></td>
</tr>



</center>
<?php
}
}
catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
}
}

?> 
<tr>


</tr>
     </table> </br> </br>




</div>  
</div>
</div>
<?php include('script.php'); ?>
<?php include('modal.php'); ?>
<?php include('add_modal.php'); ?>
<script src="custom.js"></script>

1 个答案:

答案 0 :(得分:0)

所以,我试过这个并且它有效:

  • 脚本必须按顺序排列(如果不是,它会破坏)
  • 您的模式存在一些问题,但使用Datepicker,无论如何都不需要它
  • 在FROM日期选择之后,我会将TO日期的minDate设置为+ 1d

代码示例:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <title>Document</title>
</head>
<body>
    <form action="total_sales.php" method="post">
        From:
        <input type="text" class="datepicker" placeholder="E.G.(2018-01-14)" name="dayfrom" required > To:
        <input type="text" class="datepicker" placeholder="E.G.(2018-02-11)" name="dayto" required >
        <input type="submit" value="Show Sales" name="salesbtn">
    </form>

    <script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
    <script src="http://code.jquery.com/ui/1.8.21/jquery-ui.min.js"></script>
    <script>
        $(function () {
            $(".datepicker").datepicker({
                dateFormat: "yy-mm-dd",
                minDate: "-1d",
                maxDate: "+1w"
            });
        });
    </script>
</body>
</html>