doutuzhuohao6449 2015-06-23 14:01
浏览 68

Laravel使用不同的数据库查询加入

I am constructing this query in my Laravel controller;

$payments = DB::table('payments')->leftJoin('postcodes.201502_postcode', 'payments.Vendor ZIP', '=', '201502_postcode.postcode');

    foreach ($input as $key => $value) {
        $payments = $payments->leftJoin('postcodes.pc_'.$key, '201502_postcode.'.$key, '=', 'pc_'.$key.'', 'code');
    }

    foreach ($input as $key => $value) {
        $payments = $payments->orWhereIn('pc_'.$key.'.code', $input[$key]);
    }

    $payments = $payments->select('Vendor ZIP' ,  'Input RAC' ,  'Input LPC Code' ,  'Input UIN Code')->get();

An example $input looks like this;

Array
(
[county] => Array
    (
        [0] => E10000003
        [1] => E10000006
    )

[locauth] => Array
    (
        [0] => E07000223
        [1] => E07000032
    )

[parlc] => Array
    (
        [0] => W07000058
        [1] => S14000003
    )

)

There are 5 fields in total. Not all five fields are required though. Above, "the User" is only searching on 3 for example.

The error I get is Unknown column 'pc_county' in 'on clause'. I'm not sure where to put my dots. Can I escape the dots?

It's getting confusing because the 201502_postcode table is in the postcodes database... and that table has a postcode field. The pc_xxxxx tables are also in this same postcodes database.

This is in a separate db to the payments table.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向