gpt4 book ai didi

php - 如何使用两个日期选择器从我的数据库获取数据。代码点火器

转载 作者:行者123 更新时间:2023-11-29 13:31:34 26 4
gpt4 key购买 nike

我想在两个日期选择器之间选择数据库中的所有数据。请帮助我了解如何在这种情况下使用 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;

}

这是我的模型

最佳答案

在代码示例中,这两个字段都被命名为 selectDate。我认为这就是您原来的查询不起作用的原因。尝试将第二个字段重命名为selectdate2

关于php - 如何使用两个日期选择器从我的数据库获取数据。代码点火器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19381109/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com