javascript - Search data between date range AND add data between predefined date range -


i trying build searching application people can see data according date range inputed, want add predefined date range , add result final output.

i have been searching solution did not figure out how it. think must have been missed something. please share knowledge me ?

fyi new in coding.

here form :

    <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 : <input id="date1" class="easyui-datebox" style="width:80px">&nbsp;&nbsp;         : <input id="date2" class="easyui-datebox" style="width:80px">&nbsp;&nbsp;         <a href="#" id="aaa" class="easyui-linkbutton" iconcls="icon-search">cari</a>     </div> </div> 

script function :

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();     (var = 1; <= r.length; i++) {         x.unshift(r[i - 1]);         if (i % 3 == 0 && != r.length) x.unshift(sep);     }     return "rp " + s + x.join("") + (num[1] ? dec + num[1] : ""); } 

and action :

$begin_date = '2015-07-01'; $start_date = $_request['start_date']; $end_date = $_request['end_date'];  include '../../libs/conn.php';  $rs = mysql_query("select count(*) beli tgl_po between '$begin_date' , '$start_date' , tgl_po between '$start_date' , '$end_date'"); $row = mysql_fetch_row($rs); $result["total"] = $row[0];  $rs = mysql_query("select * beli tgl_po between '$begin_date' , '$start_date' , tgl_po between '$start_date' , '$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) value_sum beli tgl_po between '$begin_date' , '$start_date' , tgl_po between '$start_date' , '$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); 

your query has

  , tgl_po between '$begin_date' , '$start_date'   , tgl_po between '$start_date' , '$end_date' 

the way sql works, need or rather and here.

  ,    (    tgl_po between '$begin_date' , '$start_date'            or tgl_po between '$start_date' , '$end_date') 

if mention and in clause, accepts records matching both criteria. if want match either criterion, need or.

you want rows matching either first date range or second. must specify or, not and. it's typical in sql queries and narrows selection , or widens it.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -