【发布时间】:2020-02-14 16:32:58
【问题描述】:
我有一个为客户加载发票的页面。我添加了一个日期选择器来按日期搜索,但是当页面加载时它不会提供任何数据,直到从表单应用过滤器。我希望页面首先加载所有数据,然后如果用户想按日期过滤,他们可以选择它。
<form method='post' action='invoices.php' class='sdate'>
<div class="sdate">
<input type="text" name="sdate" placeholder="Start Date" >
</div>
<div class="sdate">
<button type="submit" class="sdatebtn">Submit</button>
</div>
</form>
数据库查询
FROM imw_locations l
INNER JOIN vzw_invoice i
ON l.AddressCode=i.ItemCustomerFullName
WHERE l.owner='" . $owner . " ' AND Txndate='".$sdate."'
查询的完整数据
<head>
</head>
<?php
session_start();
if (!isset($_SESSION['loggedin'])) {
header('Location: /index.php');
exit();
}
?>
<?php
include "config.php";
$owner = $_SESSION['role'];
$sdate = $_POST['sdate'];
$edate = $_POST['edate'];
?>
<?php include "../../assets/navbar.php" ?>
<div>
<?php echo $sdate;?>
<!---- Date Selections ---->
<form method='post' action='invoices.php' class='sdate'>
<div class="sdate">
<input type="text" name="sdate" placeholder="Start Date">
</div>
<div class="sdate">
<input type="text" name="edate" placeholder="End Date" >
</div>
<div class="sdate">
<button type="submit" class="sdatebtn">Submit</button>
</div>
</form>
<!---- This is the download form ---->
<form method='post' action='../finance/export/download.php'>
<input type='submit' value='Export' name='Export'>
<table class="invoice">
<thead>
<tr>
<th>Reference Number</th>
<th>Memo</th>
<th>Trans. Date</th>
<th>Location</th>
<th>Item Amount</th>
<th>Quantity</th>
<th>Vendor</th>
</tr>
</thead>
<?php
$owner = $_SESSION['role'];
$query = "SELECT l.AddressCode,
l.owner,
l.City,
l.State,
l.Zip,
i.RefNumber,
i.memo,
i.Txndate,
i.DueDate,
i.ItemCustomerFullName,
i.PO_number ,
i.ItemAmount,
i.PO_number,
i.preorder_,
i.Quantity,
i.Vendor,
i.balance
FROM imw_locations l
INNER JOIN vzw_invoice i
ON l.AddressCode=i.ItemCustomerFullName
WHERE l.owner='" . $owner . " '
AND Txndate='".$sdate."'
";
$result = mysqli_query($con,$query);
$user_arr = array();
while($row = mysqli_fetch_array($result)){
$ref = $row['RefNumber'];
$memo = $row['memo'];
$Txndate = $row['Txndate'];
$duedate = $row['DueDate'];
$ItemCustomerFullName = $row['City'];
$PO_number = $row['PO_number'];
$ItemAmount = $row['ItemAmount'];
$preorder_ = $row['preorder_'];
$Quantity = $row['Quantity'];
$Vendor = $row['Vendor'];
$balance = $row['balance'];
?>
<tr>
<td><?php echo $ref; ?></td>
<td><?php echo $memo; ?></td>
<td><?php echo $Txndate; ?></td>
<td><?php echo $ItemCustomerFullName; ?></td>
<td><?php echo $ItemAmount; ?></td>
<td><?php echo $Quantity; ?></td>
<td><?php echo $Vendor; ?></td>
</tr>
<?php
}
?>
</table>
<?php
$serialize_user_arr = serialize($user_arr);
?>
<textarea name='export_data' style='display: none;'><?php echo $serialize_user_arr; ?></textarea>
</form>
</div>
【问题讨论】:
-
你能显示查询数据库的代码吗?基本上,您需要查看是否设置了日期,然后将其包含在 DB 查询的
WHERE子句中。可能发生的情况是您查询日期为 NULL 的位置,它返回空 -
@Ice76 我已经用查询更新了我的帖子
-
附注。
array($ref,$memo,$Txndate,$duedate,$ItemCustomerFullName,$PO_number,$ItemAmount,$preorder_,$Quantity,$Vendor,$balance);本质上等于$row。你可以摆脱一大堆无用的代码 -
between 可能不起作用,因为 $_POST['edate'] 似乎没有对应的表单字段。我也很疑惑为什么 echo $email;在 sdate 字段中。该代码看起来像是由几个随机代码部分组成的科学怪人版本。是吗?
-
请不要通过破坏您的帖子为他人增加工作量。通过在 Stack Exchange (SE) 网络上发帖,您已根据 CC BY-SA license 授予 SE 分发内容的不可撤销权利(即无论您未来的选择如何)。根据 SE 政策,分发非破坏版本。因此,任何破坏行为都将被撤销。请参阅:How does deleting work? …。如果允许删除,则帖子下方左侧有一个“删除”按钮,但仅在浏览器中,而不是移动应用程序中。