【发布时间】:2015-07-18 07:15:30
【问题描述】:
我正在尝试构建一个搜索应用程序,人们可以根据输入的日期范围查看数据,但我也想添加预定义的日期范围并将此结果添加到最终输出中。
我一直在寻找解决方案,但我不知道该怎么做。我想我一定错过了什么。有人可以帮我分享一下知识吗?
仅供参考,我是编码新手。
这是我的表格:
<table id="tbl_rekapbeli" class="easyui-datagrid" style="width:900px;height:360px"
url="get_lap_beli2.php" pagination="true" idField="id"
title="Rekap Pembelian Berkala" toolbar="#tb"
singleSelect="true" fitColumns="true" showFooter="true">
<thead>
<th field="no_po" width="50" editor="{type:'validatebox',options:{required:true}}">No PO</th>
<th field="tgl_po" width="50" editor="{type:'datebox',options:{required:true}}">Tgl PO</th>
<th field="nama_outlet" width="50" editor="{type:'validatebox',options:{required:true}}">Customer</th>
<th field="kode_barang" width="50" editor="{type:'validatebox',options:{required:true}}">Kode Barang</th>
<th field="nama_barang" width="90" editor="{type:'validatebox',options:{required:true}}">Nama Barang</th>
<th field="qty_beli" width="50" editor="{type:'validatebox',options:{required:true}}">Jumlah beli</th>
<th field="harga_beli" width="50" editor="{type:'validatebox',options:{required:true}}">Harga beli</th>
<th field="jum_harga_beli" width="50" formatter="formatrp" editor="{type:'numberbox'}">Total</th>
</tr>
</thead>
</table>
<div id="tb" style="padding:5px;height:auto">
<div>
Date From : <input id="date1" class="easyui-datebox" style="width:80px">
To : <input id="date2" class="easyui-datebox" style="width:80px">
<a href="#" id="aaa" class="easyui-linkbutton" iconCls="icon-search">Cari</a>
</div>
</div>
函数脚本:
var d1 = 0
var d2 = 0
$('#date1').datebox({
onSelect: function (date) {
d1 = date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate();
}
})
$('#date2').datebox({
onSelect: function (date) {
d2 = date.getFullYear() + "/" + (date.getMonth() + 1) + "/" + date.getDate();
}
})
$('#aaa').click(function () {
$('#tbl_rekapbeli').datagrid('options').url = "get_lap_beli2.php?start_date=" + d1 + "&end_date=" + d2;
$('#tbl_rekapbeli').datagrid('reload');
//alert(“dari: ” + d1 + ” sampai: ” + d2);
})
function formatrp(val, row) {
return number_format(val, '', ',', '.');
};
function number_format(num, dig, dec, sep) {
x = new Array();
s = (num < 0 ? "-" : "");
num = Math.abs(num).toFixed(dig).split(".");
r = num[0].split("").reverse();
for (var i = 1; i <= r.length; i++) {
x.unshift(r[i - 1]);
if (i % 3 == 0 && i != r.length) x.unshift(sep);
}
return "Rp " + s + x.join("") + (num[1] ? dec + num[1] : "");
}
对于行动:
$begin_date = '2015-07-01';
$start_date = $_REQUEST['start_date'];
$end_date = $_REQUEST['end_date'];
include '../../libs/conn.php';
$rs = mysql_query("SELECT count(*) FROM beli WHERE tgl_po between '$begin_date' and '$start_date' AND tgl_po between '$start_date' and '$end_date'");
$row = mysql_fetch_row($rs);
$result["total"] = $row[0];
$rs = mysql_query("SELECT * FROM beli WHERE tgl_po between '$begin_date' and '$start_date' AND tgl_po between '$start_date' and '$end_date'");
$items = array();
while($row = mysql_fetch_object($rs)){
array_push($items, $row);
}
$result["rows"] = $items;
$rs = mysql_query("SELECT SUM(jum_harga_beli) AS value_sum FROM beli WHERE tgl_po between '$begin_date' and '$start_date' AND tgl_po between '$start_date' and '$end_date'");
$rw = mysql_fetch_assoc($rs);
$sum = $rw['value_sum'];
$result["footer"]=array(array("harga_beli" => "Total Pembelian",'jum_harga_beli' => $sum));
echo json_encode($result);
【问题讨论】:
-
运行时得到什么结果?任何错误输出?在任何人开始在他们自己的沙箱中运行此代码之前,发布运行代码的结果总是一种很好的礼仪。也可能存在配置问题。
-
它仅显示所选日期范围内的数据,但我希望将预定义日期范围内的数据(从 2015-07-01 到开始日期)也添加到最终输出中
标签: javascript php mysql fifo stock