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>
SCRIPT代码如何将当前客户端ID放在这里?
$(document).ready(function() {
$('.search i').click(function() {
$(this).parent().find('input').click();
});
updateConfig();
function updateConfig() {
var options = {};
// remove other code for space
$('#config').daterangepicker(options, function(start, end, label) {
var startDate = start.format('YYYY-MM-DD'); var endDate = end.format('YYYY-MM-DD');
var cid = $(this).data("cid");
passDate(startDate,endDate,cid);
});
}
});
function passDate(startDate,endDate,cid) {
$('.loader').show();
$.ajax({
type: 'POST', // define the type of HTTP verb we want to use (POST for our form)
url: 'invoiceresult.php', // the url where we want to POST
data: 'startDate='+startDate+'&endDate='+endDate+'cid='+cid, // our data object
})
// remove for space
}
}
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
SCREENSHOT enter image description here
使用此代码,结果为&#34; undefined&#34;希望有人会帮忙。感谢
答案 0 :(得分:0)
将数据属性添加到一个元素,例如输入#config,带有client_id。然后你可以在javascript中阅读并使用它。
<强> HTML 强>
<input id="config" class="form-control placeholded" placeholder="Select the date to filter records" type="text" data-client-id="client_id" />
<强> JS 强>
$('#config').daterangepicker(options, function(start, end, label) {
var startDate = start.format('YYYY-MM-DD'); var endDate = end.format('YYYY-MM-DD');
passDate(startDate,endDate, document.getELementById("config").getAttribute("data-client-id"));
});