日期范围与admin模块无法正常工作,to,功能无法正常工作

时间:2018-04-03 07:10:35

标签: php

我不知道代码有什么问题,当我从3月3日 - 3月12日搜索时,3月12日的交易没有显示。 非常感谢,这对我很有帮助。 我想要的是显示3月12日的交易,例如如下。 我希望它显示从此日期到所选日期的交易。 例如。

This is where I input it 图1

March 3-12 Sample 图2

March 3-13 Sample 图3

这是我的代码

<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 = date('Y-m-d', strtotime($_POST['dayfrom']))." 00:00:01";
$to = date('Y-m-d', strtotime($_POST['dayto']))." 23:59:59";
?>


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

   </br> </br>
<td style="color:red;" align="center"> Total:<?php 
try {
require ("conn.php");
$stmt = $conn->prepare("SELECT SUM(sales_total) as 'test' FROM sales WHERE sales_date BETWEEN '$from' AND '$to'");
$stmt->execute();
$row=$stmt->fetch(PDO::FETCH_ASSOC);
echo $row['test'];
}
catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
}
?> 
</table>
</div>
</div>
</div>
<?php include('script.php'); ?>
<?php include('modal.php'); ?>
<?php include('add_modal.php'); ?>
<script src="custom.js"></script>

1 个答案:

答案 0 :(得分:0)

问题出现了,因为您将$to值转换为DATE,这意味着TIME部分为00:00:00。然后BETWEEN失败,因为'2018-03-12 11:31:25'不是&lt; = '2018-03-12 00:00:00'

CAST $to更改为DATETIME可以解决问题。即。

$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 DATETIME) order by inventory_date desc ");