duanjiao3754 2018-04-04 05:55
浏览 59
已采纳

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

What to add in my query to restrict users from choosing wrong dates ,

E.G. From March 7 To March 2 , the transaction within march 2-7 does not show up ,but when you change it to march 7 to april 7 it shows all transaction , is there anything that I can add to restrict users from doing that.

Please help me.

Thank you very much.

This is my sales.php file where the user will choose what date to show.

 <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>

This is my total_sales.php file.

   <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条回答 默认 最新

  • dshxbrzgi090608692 2018-04-04 07:07
    关注

    So, I tried this and it worked:

    • the scripts HAVE TO BE in that order (if not it will break)
    • There is some problem with your pattern, but with Datepicker, you don't need it anyway
    • After the FROM Date selection I would set the minDate of the TO Date to +1d

    Code Example:

    <!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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog