retrieve database values based on dates using ajax codeigniter php

260
November 26, 2016, at 9:33 PM

I want to retrieve database values using ajax based on date range selected on the form by using codeigniter. The scenario is very straight forward. when the user select the daterange from the datepicker the desired system should callback to DB for retrieveing specific student's report and fill the bootstrap table with retrieved values to new without reloading the page for getting data. view page of attendance checkout

attendance table on database

Answer 1

Php query,

select *
from table_name
where date(date) between date('from date') and date('to date')

Ajax for this

$("#generate").on('click', function (e) {
    e.preventDefault();
    $.ajax({
        url: 'path to controller method',
        type: 'post',
        data: {fromdate:$("#fromdate").val(),todate:$("#todate").val()},
        success: function (data) {
              alert(data);
        }
    });
});

For generate button give id as generate, also give from from date and to date

echo the content in controller, it will come in ajax success in data. you can append to required div.

Answer 2

function get_attendance_report(){ 
        $studentid =$_POST['studentid']; 
        $fromdate = date("Y-m-d", strtotime($_POST['fromdate'])); 
        $todate = date("Y-m-d", strtotime($_POST['todate'])); 
 
        $this->db->where('date >=', $fromdate); 
        $this->db->where('date <=', $todate); 
        $this->db->where('student_id =', $studentid); 
        $attendance_reports = $this->db->get('attendance')->result_array(); 
 
 
        foreach ($attendance_reports as $row){ 
            echo '<tr>'; 
            echo  '<td>'.$row['date'].'</td>'; 
            echo   '<td>'.$row['status'].'</td>'; 
            echo   '<td>'.$row['remarks'].'</td>'; 
            echo '</tr>'; 
        } 
         
    }

This is how i done it ... Thank You so much @Niranjan

Rent Charter Buses Company
READ ALSO
How to add touch and swipe to my product slider

How to add touch and swipe to my product slider

I am trying to add touch & swipe feature to my product sliderHow can I enable this feature? I'm also using jQuery UI Touch Punch and

497
HTML onchange with range firing like oninput

HTML onchange with range firing like oninput

I read an articel from http://wwwimpressivewebs

522
Select2: Getting ajax data attributes from selected value

Select2: Getting ajax data attributes from selected value

I'm using Select2 40 as the code update has broken some existing code:

651
Click the button to enable the input next to it in jQuery

Click the button to enable the input next to it in jQuery

i found the tutorial like this but when I add the input, second input dont want to enable

359