dongpou7275 2016-01-03 16:44
浏览 160

Lumen / Laravel查询构建器 - BETWEEN

I'm attempting to convert this tradtional sql query to larvael/lumen query builder and running into brick walls.

$query = "SELECT a.id, a.name, a.cuisine, a.status, a.new, a.addressLine1, a.addressLine2, a.addressLine3, a.city, a.weekendot, a.weekendct, b.class
    FROM restaurants a, restaurants_class b
    WHERE a.class = b.id
    AND '$date' = CURRENT_DATE
    AND '$ntime' BETWEEN a.weekendot AND a.weekendct
    ORDER BY id DESC";

$date and $ntime are variables.

This is what I have so far;

$posts = DB::connection('web')
        ->table('restaurants')
        ->join('restaurants_class', 'restaurants.class', '=', 'restaurants_class.id')
        ->select('restaurants.*', 'restaurants_class.*')
        ->get();

The first AND statement is not getting anything from the DB

The second AND statement is comparing a var to two columns in the DB

Not sure how to implement the whereBetween

  • 写回答

1条回答 默认 最新

  • drfm55597 2016-01-03 22:43
    关注

    This is completely untested but I think your best bet is to use whereRaw method as you have variables which would not allow you to use the whereBetween method.

    I'm also assuming that the $date and $ntime variables are PHP variables and not MySQL variables.

    $posts = DB::connection('web')
           ->table('restaurants')
           ->join('restaurants_class', 'restaurants.class', '=', 'restaurants_class.id')
           ->whereRaw('? = CURRENT_DATE', $date)
           ->whereRaw('? BETWEEN a.weekendot AND a.weekendct', $ntime)
           ->select('restaurants.*', 'restaurants_class.*')
           ->get();
    
    评论

报告相同问题?

悬赏问题

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