Php ajax调用daterangepicker中的where子句

Php ajax调用daterangepicker中的where子句,php,jquery,html,ajax,daterangepicker,Php,Jquery,Html,Ajax,Daterangepicker,HTML代码 <div class="col-md-4 input-group input-group-lg search"> <span class="input-group-addon"><i class="fa fa-fw fa fa-calendar red"></i></span> <input id="config" class="form-control placeholded" placeh

HTML代码

  <div class="col-md-4 input-group input-group-lg search">
     <span class="input-group-addon"><i class="fa fa-fw fa fa-calendar red"></i></span>
     <input id="config" class="form-control placeholded" placeholder="Select the date to filter records" type="text" data-cid="<? echo $cid; ?>">
   </div>
PHP语句是WHERE子句

 if((!empty($_POST['startDate'])&&(!empty($_POST['endDate'])))) {   // Check whether the date is empty          
    $startDate = date('Y-m-d',strtotime($_POST['startDate']));
    $endDate = date('Y-m-d',strtotime($_POST['endDate']));
    $cid = $_POST['cid'];
    $sresult = $db->prepare('SELECT * FROM invoice WHERE (invoiceCreated BETWEEN  "'.$startDate.'" and "'.$endDate.'") AND cid=:cidg');  // Execute the query
    $sresult->execute(array(":cidg)=>$cid);
    $num_rows = $sresult->fetchColumn(); //Check whether the result is 0 or greater than 0.
    // remove other code for space
截图


使用此代码,结果未定义,希望有人能提供帮助。谢谢

使用您的客户端id为一个元素(例如inputconfig)添加一个数据属性。然后您可以在javascript中读取它并使用它的值

HTML

JS

$'config'.daterangepickeroptions,函数开始,结束,标签{ var startDate=start.format'YYYY-MM-DD';var endDate=end.format'YYYY-MM-DD'; passDatestartDate,endDate,document.getELementByIdconfig.getAttributedata-client-id;
};

您当前正在基于时间进行搜索,您的id在主页上的什么位置?会触发什么事件来获取基于id的信息?“我只想获取当前客户的id”-从哪里来?感谢回复。。。在截图上。顺便说一句,我只需要在ajax调用之前或内部获取特定的公司/客户ID。目前,通过该代码,我可以获取所有发票,包括所有客户/公司。在链接viewinvoices.php?cid=80160001中,它已经有了一个id,但是当ajax调用invoiceresult.php时,调用后留下的id。明白了,但是我需要在ajax调用数据中传递该id吗:?$。ajax{type:'POST',//定义我们希望在表单url中使用POST的HTTP谓词的类型:'invoiceresult.php',//我们希望发布数据的url:'startDate='+startDate+'&endDate='+endDate,//我们的数据对象}是。一种方法是数据:'startDate='+startDate+'&endDate='+endDate+'clientId='+client-id'。另一种方法是使用变量,如var data={startDate:startDate,endDate:endDate,clientId:client-id};我插入了以下代码passDatestartDate、endDate、document.getELementByIdconfig.getAttributedata-client-id;数据:'startDate='+startDate+'&endDate='+endDate+'cid='+cid,仍然不是工作伙伴。。。无论如何,这里是查询:$sresult=$db->prepare'SELECT*FROM invoice,其中invoice是在“$startDate.”和“$endDate.”之间创建的,cid=:cidg';//执行查询$sresult->executearray:cidg=>$cid;你也编辑过你的函数吗?函数passDatestartDate、endDate、cid{另外,getELementById是错误的,getELementById是正确的。你的错误消息是什么?你能用你的新代码更新你的发帖吗?嗨,伙计,刚刚更新了新代码,但仍然没有结果。更新后的代码会显示日期选择器,但$'.loader'.show;不会显示,它挂起了…:
 if((!empty($_POST['startDate'])&&(!empty($_POST['endDate'])))) {   // Check whether the date is empty          
    $startDate = date('Y-m-d',strtotime($_POST['startDate']));
    $endDate = date('Y-m-d',strtotime($_POST['endDate']));
    $cid = $_POST['cid'];
    $sresult = $db->prepare('SELECT * FROM invoice WHERE (invoiceCreated BETWEEN  "'.$startDate.'" and "'.$endDate.'") AND cid=:cidg');  // Execute the query
    $sresult->execute(array(":cidg)=>$cid);
    $num_rows = $sresult->fetchColumn(); //Check whether the result is 0 or greater than 0.
    // remove other code for space