[英]how can I fetch the Ids from one table to another using the DashboardController and js
i've two tables; 我有两张桌子;
exam_Marks table Exam_Marks表
{id, codeid, examMarks}
examCodes table ExamCodes表
{id, codes, codeDesc}
am trying to fetch the id of codes from table examCodes and pass them to exam_marks table, however I can't earn this and i don't know where the problem is. 我试图从表examCodes中获取代码ID,并将其传递给exam_marks表,但是我无法赚到这个,而且我也不知道问题出在哪里。 can anyone please help or advice me to use another method
任何人都可以请帮助或建议我使用其他方法吗
this is my app.js 这是我的app.js
$scope.examcodesList = function() {
dataFactory.httpRequest(
'dashboard/examcodeList',
'POST',
{},
{"classes":$scope.form.codes}
)
.then(function(data) {
$scope.subje = data.subje;
});
}
and this is my DashboardController.php 这是我的DashboardController.php
public function examcodesList($classes = ""){
$examcodesList = array();
if(!Input::has('classes')){
return $examcodesList;
}
$classes = Input::get('classes');
if(is_array($classes)){
return examcodes::whereIn('id',$classes)->get()->toArray();
}else{
return examcodes::where('id',$classes)->get()->toArray();
}
}
Try with this. 试试这个。 Not sure that's what you actually want.
不确定那是您真正想要的。
if(is_array($classes)){
return examcodes::join('exam_Marks', 'exam_Marks.codeid', '=', 'examCodes.id')
->whereIn('id',$classes)
->get()->toArray();
}else{
return examcodes::join('exam_Marks', 'exam_Marks.codeid', '=', 'examCodes.id')
->where('id',$classes)
->get()->toArray();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.