这是我的两张桌子:
company_industry_type:

law_master:

表company_industry_type有分配给特定id的列lm_id。
我想从lm_id表law_master中获取有关分配给表company_industry_type id的lm_id
请帮我一把,我刚开始吃拉拉。
<?php
$law = DB::table('tbl_company_industry_type')->pluck('lm_id');
$law_d = DB::table('tbl_law_master')->whereIn('id',$law)
->select('id','lm_id','law_name')->get();
$res_lms = '';
foreach($law_d as $law_details)
{
?>
<span id="sublaw_data">{{ $law_details->lm_id }}
({{ $law_details->law_name }}) <i class="fa fa-remove deleteclass"
onclick="delete_law('<?php echo $law_details->id?>')"></i></span>
<?php
$res_lms .=$law_details->id.",";
}
$res_lawids=trim($res_lms,',');
?>我的代码只返回一个id的数据,即1,而不返回最后一个company_industry_type记录的3,4
发布于 2017-11-07 09:51:30
使用下面的查询,您可以根据您的需求获得结果。
DB:表(‘company_industry_type’) ->join('company_industry_type‘、’company_industry_type.law_id‘、'=’、'law_master.lm_id') ->select(‘law_master.lm.law_id’、‘law_master.lm.law_name’、'company_industry_type.*') ->get();
https://stackoverflow.com/questions/47154449
复制相似问题