报告中的日期范围,由于查询而无法正常工作
Posted
技术标签:
【中文标题】报告中的日期范围,由于查询而无法正常工作【英文标题】:Date range from reports , not working properly because of query 【发布时间】:2018-09-13 14:06:44 【问题描述】:在我的查询中添加什么来限制用户选择错误的日期,
例如从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 cellspacing="0" cellpadding="0" style="font-family:Arial Narrow, Arial,sans-serif; font-size:15px;" border="1">
<tr>
<td ><div align="center"><strong>Purchase Date</strong></div></td>
<td ><div align="center"><strong>Customer</strong></div></td>
<td ><div align="center"><strong> Purchase Name</strong></div></td>
<td ><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>
【问题讨论】:
由于您使用的是日期选择器,您可以参考jqueryui.com/datepicker/#date-range 日期选择器无法正常工作 为什么日期选择器不工作?您收到什么错误消息? 没有具体的错误信息,只是日历不会显示 【参考方案1】:所以,我尝试了这个并且成功了:
脚本必须按此顺序排列(否则会中断) 您的模式存在一些问题,但使用 Datepicker,您无论如何都不需要它 在选择 FROM Date 之后,我会将 TO Date 的 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>
【讨论】:
你能帮我在我的代码中使用它吗?我很难搞清楚 好的,尝试将所有 它现在可以工作了,谢谢你们谢谢@domenik Reitzner以上是关于报告中的日期范围,由于查询而无法正常工作的主要内容,如果未能解决你的问题,请参考以下文章