我想从我的两个日期选择器之间的数据库中选择所有数据。请帮助我了解如何在这种情况下使用 BETWEEN AND 语句。我从第一个日期选择器中选择一个日期,然后显示数据,但是当我在第二个日期选择器上选择一个日期时,第二个日期选择器中的日期数据只显示第一个日期消失了
我用了这个查询
$this->db->where('date_sold >=',$this->input->post('selectdate'));
$this->db->where('date_sold <=',$this->input->post('selectdate2'));
但我只得到1个数据..
<span>Select 1st sem:</span>
<div id="datetimepicker1" class="input-append date">
<input data-format="MM/dd/yyyy" type="text" readonly name="selectDate" id="selectDate"></input>
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar">
</i>
</span>
</div>
<script type="text/javascript">
$(function(){
var date = new Date();
date.setDate(date.getDate());
$('#datetimepicker1').datetimepicker({
pickTime: false
});
});
</script>
<span>Select 2st sem:</span>
<div id="datetimepicker2" class="input-append date">
<input data-format="MM/dd/yyyy" type="text" readonly name="selectDate" id="selectDate2"></input>
<span class="add-on">
<i data-time-icon="icon-time" data-date-icon="icon-calendar">
</i>
</span>
</div>
<script type="text/javascript">
$(function(){
var date = new Date();
date.setDate(date.getDate());
$('#datetimepicker2').datetimepicker({
pickTime: false
});
});
</script>
/这是我的看法
function get_semreportdata(){
$q = $this->db->select('
books.title,
reserved_books.id,
reserved_books.isbn,
reserved_books.price,
reserved_books.item_sold,
reserved_books.date_sold,
reserved_books.total_amount
')
->from('reserved_books')
->join('books','reserved_books.isbn= books.isbn')
->where('date_sold >=',$this->input->post('selectdate'))
->where('date_sold <=',$this->input->post('selectdate2'));
$reserved['rows'] = $q->get()->result();
$this->db->select_sum('total_amount');
$this->db->where('date_sold',$this->input->post('selectdate'));
$query = $this->db->get('reserved_books');
$reserved['total'] = $query->result();
return $reserved;
}
这是我的模型