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
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.
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
</div>
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>';
}
}
</div>