Link to home
Start Free TrialLog in
Avatar of David Schure
David Schure

asked on

Filtering by Date

I am trying to filter a report based on the month from a select box.
The query for the report
$sql = <<<EOT
    SELECT DATE_FORMAT(tbl_session.session_date,"%W, %M, %d, %Y") AS DATE, 
   TIME_FORMAT(CONCAT(tbl_session.time_slot_id, ":00:00"), "%h:%i %p") AS TIME,
   tbl_session.session_type AS TYPE, tbl_therapist.therapist_name as THERAPIST, tbl_session.session_status AS STATUS
    FROM tbl_session
    INNER JOIN tbl_therapist
    ON tbl_therapist.therapist_id=tbl_session.therapist_id
   WHERE tbl_session.client_id=$client_id
AND tbl_session.session_date = (NOT SURE WHAT GOES HERE)
    ORDER BY session_date DESC;
EOT;
$result = $db->query($sql);

Open in new window

The selectbox
<form action="monthselect.php">
  <label for="monthly">Select a Month</label>
 
  <select name="monthly" id="monthly">
     <option value="All">Show All</option>
    <option value="Jan">January</option>
    <option value="Feb">February</option>
    <option value="Mar">March</option>
    <option value="Apr">April</option>
    <option value="May">May</option>
    <option value="Jun">June</option>
    <option value="Jul">July</option>
    <option value="Aug">August</option>
    <option value="Sept">September</option>
    <option value="Oct">October</option>
    <option value="Nov">November</option>
    <option value="Dec">December</option>
  </select>
   <input type="submit" value="Submit"> 
</form>

Open in new window

I know I need to add an Ajax script and populate the monthselect.php file.  Not sure how.
<script>
      $('select[name=monthly]').on('change', function() {

    let selectedValue = $(this).val()
    $.ajax({
        url : 'monthselect.php',
        data : { client : selectedValue },
    }).done(function(response) {
        console.log(response);
      $('#results').html(response);
    })

})
      </script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of David Schure
David Schure

ASKER

Thank you, That works  when I hard code it. but how and where do I create your value? That is the next question.