Cant pull data report by only between dates?


I thought I have all the codes correct to pull a report by between dates and by But the filter message No Order Found. How to get the filter_class.php select where by = index_class.php dropdown selected numeric value. I’ve been searching and trying everything I’ve learned no success. Any help would be appreciated. If I put the number in the filter_class.php select where by = 4 manually, it will pull the report by that number. But it needs to pull the report based on the dropdown list on index_class.php.
I can pull the report just fine with the datepicker between dates, but I need it to pull by date and number.
codes below


       <div class="col-md-3">
       <input type="text" name="from_date" id="from_date" class="form-control" placeholder="From Date" />

       <div class="col-md-3">
       <input type="text" name="to_date" id="to_date" class="form-control" placeholder="To Date" />

        <div class="col-md-3"> 
       <input type="button" name="filter" id="filter" value="Filter" class=".btn-mini btn-info" /> 

Dropdown that pulls data from database _person_group table

    <div class="col-md-4"> 

    $(document).ready(function() {
    $.getJSON("classes-data.php", function(return_data){
        $.each(, function(key,value){
        $("#class").append("<option value=" + +">""</option>");    


    //var st=$('#class option:selected').text();
    var st=$('#class').val();

    <select id=class id=class>


require "config.php"; // Database Connection

$sql="select  id, name  from _person_group "; 

echo json_encode(array('data'=>$result));


///////// Database Details change here  ////
$dbhost_name = "localhost";
$database = "databasename";
$username = "root";
$password = "password";
//////// Do not Edit below /////////
try {
$dbo = new PDO('mysql:host=localhost;dbname='.$database, $username, $password);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage();

Datepicker code

                dateFormat: 'yy-mm-dd'   
                var from_date = $('#from_date').val();  
                var to_date = $('#to_date').val();
                if(from_date != '' && to_date != '')
                          data:{from_date:from_date, to_date:to_date},  
                     alert("Please Select Date");  


     $query = "
                    SELECT * FROM attendance_record, _person,  _person_group
                   WHERE = attendance_record.personid AND = $('#class').val()
    and date BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."' 


            $result = mysqli_query($conn, $query);

by date and class picked


First and foremost, prepared statements. I am a stickler for them because of security issues.

In your sql you have, $(’#class’).val(). That doesn’t exist.

So, how it happens is:

Php runs first. It renders the page after whatever processing and then sends it to the browser. JQuery (JavaScript) runs entirely in the browser. So you are trying to get a value from the browser, before the browser has anything.


The = $(’#class’).val() was a failed attempt to get it to pull.

If I put in there =4, which is the id for young marrieds, it will pull the data.
I cant figure the code to put after =., so it will pull the correct group from the dropdown selection.
Thank You


You need to pass it in thru the ajax function that calls the API.


Thank you for the response’s, maybe I’m confusing this. It works by date, just not by
I need the report to pull all persons that where in a selected class and the between date.


And the ajax call passes in the dates, but nothing else.


Should be in the ajax.

Add this to the top of the php page that gets the request.


And then in the ajax function make these modifications,

               group: $('#class').val()


Ok we are getting closer, I did as you said. Now it pulls the report by date and by, but if I change the class dropdown selection to another class it still pulls the report for that same person in that class. I only have 1 person in 1 class currently to test.
And that person (Bill Hughes) is only in young marrieds class and only attended on 9/2/2018.

Working correct

So close we are!!!


Not Working correct
should say > No Order Found, because Bill Hughes is not in this class.

Sorry had to reply twice, because I’m new, and it will only let me post 1 image per post.


tables below, hope this helps



Are the values changing for the group id first of all?


Yes. I can change the selection and it changes the class. But it shows the only person (Bill Hughes) is in every class.


You need to revisit your query. You need an inner join


Ok I revisited my query and found I needed to add
WHERE attendance_record.groupid =
All working as desired, thank you astonecipher for all your help.


 $query = "
                SELECT * FROM attendance_record, _person,  _person_group
               WHERE = attendance_record.personid
               AND = '".$_POST["class"]."'
AND date BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."' 


 $query = "
                SELECT * FROM attendance_record, _person,  _person_group
               WHERE attendance_record.groupid =
              AND = '".$_POST["class"]."'
AND date BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."'