簡體   English   中英

我如何使用DashboardController和js從一個表到另一個表獲取ID

[英]how can I fetch the Ids from one table to another using the DashboardController and js

我有兩張桌子;

Exam_Marks表

{id, codeid, examMarks}

ExamCodes表

{id, codes, codeDesc}

我試圖從表examCodes中獲取代碼ID,並將其傳遞給exam_marks表,但是我無法賺到這個,而且我也不知道問題出在哪里。 任何人都可以請幫助或建議我使用其他方法嗎

這是我的app.js

$scope.examcodesList = function() {
    dataFactory.httpRequest(
        'dashboard/examcodeList',
        'POST',
        {},
        {"classes":$scope.form.codes}
    )
    .then(function(data) {
        $scope.subje = data.subje;
    });
}

這是我的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();
    }
}

試試這個。 不確定那是您真正想要的。

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM