THE HTML code
<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>
THE SCRIPT code how to put the current client id here?
$(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
}
}
THE PHP this is the WHERE clause
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
with this code the result is "undefined" Hope someone will help. Thanks