日期范围不正常,特别是我认为的功能

时间:2018-04-03 04:00:10

标签: php

日期范围选择器在我的库存报告中无法正常工作,但对于销售报告,它可以正常工作。

E.g。从 2018-03-07 2018-03-08 2018-03-08 未显示在报告中。

报告图片:
Picture of the report

这是我的代码

<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>
.logo1 {
    position: absolute;
    right: 45%;
    font-family: ""Lucida Console", Monaco, monospace";
    top: 0%;
    width: 80%;
    background-color:#F8F8FF;
    color: black;
    text-align: center;

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




<?php
if(isset($_POST['salesbtn'])) {
$from=$_POST['dayfrom'];
$to=$_POST['dayto'];
?>


</head>
<body>



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

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


  <br><img src="../upload/logo.jpg"  class="logo1" style="height:50px; width:50px;" ><br>
<center><h1>Inventory Report</h1><h3>  From (<?php echo $from; ?>) To (<?php echo $to; ?>)</h3>
<br>
<button id="printPageButton" class="btn btn-primary" onClick="window.print();">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>
      <th width="25%"><div align="center"><strong> Date  </strong></div></th>
           <th width="20%"><div align="center"><strong> User</strong></div></th>
        <th width="20%"><div align="center"><strong>Action</strong></div></th>
           <th width="20%"><div align="center"><strong>Product Name</strong></div></th>
    <th width="20%"><div align="center"><strong>Quantity </strong></div></th>
      </tr> 

        <?php
          $iq=mysqli_query($conn,"select * from inventory left join product on product.productid=inventory.productid where inventory_date BETWEEN CAST('$from' AS DATE) AND CAST('$to' AS DATE) order by inventory_date desc ");
          while($iqrow=mysqli_fetch_array($iq)){


          ?>
            <tr>
              <td class="hidden"></td>
              <td><?php echo date('M d, Y h:i A',strtotime($iqrow['inventory_date'])); ?></td>  
              <td>
              <?php 
                $u=mysqli_query($conn,"select * from `user` left join customer on customer.userid=user.userid left join supplier on supplier.userid=user.userid where user.userid='".$iqrow['userid']."'");
                $urow=mysqli_fetch_array($u);
                if($urow['access']==1){
                  echo "Admin";
                }
                elseif($urow['access']==2){
                  echo $urow['customer_name'];
                }
                else{
                  echo $urow['company_name'];
                }
              ?>
              </td>
              <td align="right"><?php echo $iqrow['action']; ?></td>
              <td align="right"><?php echo $iqrow['product_name']; ?></td>
              <td align="right"><?php echo $iqrow['quantity']; ?></td>
            </tr>
          <?php
 }         }
        ?>

</tr> </td>


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

编辑:

这是我的inventory.php 在这里,用户可以从,输入范围日期。 我不知道这对你们有帮助吗。 我只是想知道为什么它不能很好地运作。 问题是当我输入2018-03-08 - 2018-03-08时,3月7日出现但行军8不会出现。

 <form action="total_inventory.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 Report" name="salesbtn" ></form>

编辑:

这是我的库存表 INVENTORY DATA TABLE

更新: 这是输出,仍然没有显示3月7日的交易 Sample Updated

1 个答案:

答案 0 :(得分:-1)

您的桌子上还有时间,所以您必须按时搜索。表示您的来自d-m-Y 00:00:01,而您的来自d-m-Y 23:59:59

更新:将这样的日期变量连接起来。

// Assume `$_POST['dayfrom'] = 03/15/2018;`
// Assume `$_POST['dayto'] = 03/31/2018;`

$from = date('Y-m-d', strtotime($_POST['dayfrom']))." 00:00:01";
$to = date('Y-m-d', strtotime($_POST['dayto']))." 23:59:59";

echo $from; // if date is `03/15/2018` output like `2018-03-15 00:00:01`
echo $to; // if date is `03/31/2018` output like `2018-03-31 23:59:59`

// NOTE: check your date format is like this or not, then run the SQL query.

更新了查询:

$iq=mysqli_query($conn,"select * from inventory left join product on product.productid=inventory.productid where ( inventory_date BETWEEN CAST('$from' AS DATE) AND CAST('$to' AS DATE) ) order by inventory_date desc ");