Inner Join laravel 5.2

时间:2017-05-03 07:26:42

标签: php mysql laravel join laravel-5

研究员,

我正在尝试使用内部联接查询从我的相关表中获取多个数据。我要做的是将{var ANI0 = [0.0,0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0]; var Mathexp; //operation inserted by the user in the webpage in a input text Mathexp = '(ANIO[i]-0.01)/20'; //Example for (i=0; I<ANIO.length; i++){ singleObj = {}; singleObj['voltage'] = eval(xScale); singleObj['current'] = eval(Mathexp); listOfObjects.push(singleObj); } //generate a jsonFILE in order to graph results with metrics graphics myJSON = JSON.stringify(listOfObjects); fs.writeFile("public/data/file.json", myJSON, function(err){ if(err){console.log(err);} else {console.log("archivo guardado..");} }); socket.emit('graphEvent',{message: ':)'}); enter code here 作为project_id - {{1作为company_name)。我尝试使用查询,我将在下面说明。我也会发布我的桌子的印刷品。

subproject_id

enter image description here

enter image description here

enter image description here

enter image description here

我希望对我的问题有所帮助,因为我不明白现在该做什么..

1 个答案:

答案 0 :(得分:3)

我认为这应该可以解决问题(如果我正确理解了你的表结构)。

我建议您阅读Joins上的官方Laravel文档。

$query = DB::table('projects')
           ->join('subprojects', 'projects.id', '=', 'subprojects.project_id')
           ->join('companies', 'projects.company_id', '=', 'companies.id')
           ->select('companies.company_name', 'projects.id', 'subprojects.id', 'subprojects.title')
           ->get();
相关问题