简体   繁体   English

在一天字段中检查两个日期之间的可用性

[英]Check availability between two dates in a day field

Helo, I am trying to get the products available between two dates through calendar table where I have relation with the product. Helo,我正在尝试通过与该产品相关的日历表在两个日期之间提供该产品。

I put the data of my table: 我把表的数据放进去:

在此处输入图片说明

在此处输入图片说明

I understand that if I do a foreach and I'm checking day by day I can get it, but I do not want it that way, I want to do it correctly with mysql 我知道,如果我做一个foreach并且每天都在检查,我可以得到它,但是我不希望这样,我想用mysql正确地做

This is the query that I am currently executing and does not give me the expected results. 这是我当前正在执行的查询,没有给我预期的结果。 this is name the my page 这就是我的页面名称

    $start_date  = fecha_mysql_slash($this->input->get('start_date'));
    $end_date    = fecha_mysql_slash($this->input->get('end_date'));
    $calendars   = new Calendar();
    $calendars->select("*")
    ->where('day BETWEEN "'.$start_date.'" AND "'.$newEndDate.'" and availability > 0')
    ->include_related("producto",NULL,TRUE,TRUE)
    ->group_by("producto_id")
    ->get()->all;

Now I will try to explain to me, through a form I get the start date and also the end date, so I have to check in the calendar table from start date to end date if exists in the field "day" and also Which has availability greater than 0., well with this query I can not get it. 现在,我将尝试通过表格向我解释开始日期和结束日期,因此我必须检查从开始日期到结束日期的日历表(如果存在于“天”字段中,并且可用性大于0。通过此查询,我无法获取它。

Currently there is no error, the problem is that I get products, when on the dates that I indicate does not exist in the table and field "day" 当前没有错误,问题是我在表和字段“ day”中指示的日期不存在时获取产品

For example I make the query through the dates 2017-03-13 and 2017-03-25, the problem that I think I do not understand because I get the product id, when from 2017-03-13 there are no records for these product. 例如,我通过日期2017-03-13和2017-03-25进行查询,我认为我不理解该问题,因为我获得了产品ID,而从2017-03-13开始,则没有这些记录产品。

I hope you can help me, 我希望你能帮帮我,

thank you very much. 非常感谢你。

You have: 你有:

$end_date    = fecha_mysql_slash($this->input->get('end_date'));

and

->where('day BETWEEN "'.$start_date.'" AND "'.$newEndDate.'" and availability > 0')

$end_date is a different variable from $newEndDate. $ end_date是与$ newEndDate不同的变量。 Change $newEndDate to $end_date and it should work. 将$ newEndDate更改为$ end_date,它应该可以工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM