0

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:- enter image description here

attendance table on database:- enter image description here

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

15 Comments

hello Nirajan .. i have implemented your suggestion but it seems not worked at all.. i have posted the whole code how i implement .. so please suggest me the right way please
@SumanDahal which part is not working?? what is alert giving??
alert doesn't gives any result at all. button is clicked but it doesn't show any alert
i have tested the alert by modifying my controller by just echo 'name'; and it shows the alert but retrieving from DB is not working ...
I think the ajax doesn't send the values to controller.. because i have also tested it with echoing the $fromdate , $todate and $studentid ... and it just show me the blank alert.
|
0

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

Comments

0

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>';
        }
        
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.