【发布时间】:2020-05-17 09:33:32
【问题描述】:
如果有值,我想从表 stage_cdl 中获取值,如果有值,我想从故事 stage_vdl 中获取值。
在此之前,我使用了这段代码(如下),但我只收到数组,直到值 5 不包括表 stage_vdl_id。
$data = DB::table('stud_stage_cdl as ssc')
->join('license_cdl_module as lcm', 'lcm.id', '=', 'ssc.l_cdl_m_id')
->join('invoice_stud as is', 'is.id', '=', 'ssc.inv_stud_id')
->where('ssc.stud_id', $postData['stud_id'])
->select(
'lcm.class_code',
'is.invoice_num',
'is.total',
'is.created_at'
)
->get();
输出:
(
[0] => stdClass Object
(
[class_code] => D
[invoice_num] => W1007INV20051
[total] => 1484.00
[created_at] => 2020-05-15 10:18:38
)
[1] => stdClass Object
(
[class_code] => B2
[invoice_num] => W1007INV20052
[total] => 1484.00
[created_at] => 2020-05-15 10:18:55
)
[2] => stdClass Object
(
[class_code] => DA
[invoice_num] => W1007INV20053
[total] => 1484.00
[created_at] => 2020-05-15 13:44:54
)
[3] => stdClass Object
(
[class_code] => B2
[invoice_num] => W1007INV20054
[total] => 1484.00
[created_at] => 2020-05-15 13:48:18
)
[4] => stdClass Object
(
[class_code] => B2
[invoice_num] => W1007INV20055
[total] => 1484.00
[created_at] => 2020-05-15 14:00:54
)
)
invoice_stud 表
stud_stage_cdl 表
stud_stage_vdl 表
license_cdl_module 表
license_vdl_module 表
这是我到目前为止所做的,没有错误但没有值输出。我对 sql 很陌生。如您所见,我正在尝试从 lcm 和 lvm 获取值。
$data = DB::table('invoice_stud as is')
->join('stud_stage_vdl as ssv', 'is.stud_id', '=', 'ssv.stud_id')
->join('stud_stage_cdl as ssc', 'is.stud_id', '=', 'ssc.stud_id')
->join('license_cdl_module as lcm', 'ssc.l_cdl_m_id', '=', 'lcm.id')
->join('license_vdl_module as lvm', 'ssv.l_vdl_m_id', '=', 'lvm.id')
->where('is.stud_id', $postData['stud_id'])
->select(
'lcm.class_code',
'lvm.class_code',
'is.invoice_num',
'is.stage_cdl_id',
'is.stage_vdl_id',
'is.total',
'is.created_at'
)
->get();
【问题讨论】: