doulong2782 2017-03-13 05:11
浏览 35

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

Helo, I am trying to get the products available between two dates through calendar table where I have relation with the product.

I put the data of my table:

enter image description here

enter image description here

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

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.

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"

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.

I hope you can help me,

thank you very much.

  • 写回答

1条回答 默认 最新

  • dpr26232 2017-03-15 22:05
    关注

    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. Change $newEndDate to $end_date and it should work.

    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探