简体   繁体   English

我如何使用DashboardController和js从一个表到另一个表获取ID

[英]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.

相关问题 我可以使用“fetch”从另一个运行 JS 脚本吗? - Can I run a JS script from another using `fetch`? AngularJs-如何使用angular.copy将值从一个输入字段取到另一个字段? - AngularJs - How can i fetch the value from one input field into another field using angular.copy? 如何使用另一个js类n-native-native的键从const中获取值? - How can i fetch a value from a const using a key from another js class n react-native? 我如何使用带有 redux 和 react.js 的按钮将数据从一个组件传递到另一个组件? - How can i pass the data from one Component to another using a button with redux and react.js? 如何将数据从一个 js 文件访问到另一个文件? - How can I access data from one js file to another? 如何使用另一个文档数组中的ID对游标进行排序? - How can I sort a cursor using ids from another document array? 如何通过一个API调用从Facebook ID列表中获取Facebook名称列表? - How do I fetch a list of Facebook names from a list of Facebook IDs with one API call? 如何使用从另一个 API 获取的数据获取数据? - How to fetch from one API using data fetched from another? 如何检查提取响应以调用另一个响应? - How can I check a fetch response to call another one? 如何从mongodb获取数据并使用节点js将其显示在表中? - how to fetch data from mongodb and display it in a table using node js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM