laravel中的简单分页?

时间:2018-07-19 05:40:32

标签: php laravel pagination

我在laravel中进行简单的分页。我正在foreach循环中从数据库中获取20条记录并进行测验。我想通过应用控制器部分中的条件来跳过两次测验之间的问题,就像我想跳过问题编号10和11。如何在简单的分页中进行?

控制器部分:

public function choosequestion(Request $request){

    if(Session::get('storepercentage')  < 60){

        $getquestion = DB::table('5question')->select('question_id','question','choice1','choice2','choice3','choice4','question_level')
                                               ->where('question_level','=','easy')
                                               ->simplepaginate(1);
    }

    if(Session::get('storepercentage')  > 60){ 

        $getquestion = DB::table('5question')->select('question_id','question','choice1','choice2','choice3','choice4','question_level')
                                               ->where('question_level','=','medium')
                                               ->simplepaginate(1);
    } 

    if($request->ajax()){

        return view('ajax',['getquestions'=>$getquestion])->render();
    }

    return view('question5',['getquestions'=>$getquestion]);
}

用于计算%的控制器输入部分:

public  function questionquiz5(Request $request){

    static $startscore=0;
    static $getscore;
    static $level;

    $getidvalue = Input::get('getid');
    $getanswervalue = Input::get('getanswer');

    $dbscore = \DB::table('5question')->select('question_id','correct_answer','question_marks','question_level')
                                      ->where('question_id','=',$getidvalue)
                                      ->get();


    foreach ($dbscore as $easy) {//////easy questions start 

        if ( $getanswervalue==($easy->correct_answer) ){

             $level = $easy->question_level;  
             $getscore  =  $startscore + $easy->question_marks;

        }elseif($getanswervalue == null){

             $getscore = 0;
             $level = $easy->question_level;   

        }else{

             $getscore = 0;
             $level = $easy->question_level;

        }

    }

    Session::push('getscoresession',$getscore);
    $score = array_sum(Session::get("getscoresession"));

    $epercentage = ($score / 8 ) * 100; 

    if($epercentage > 60){
            Session::put('storepercentage', $epercentage);
            echo "true";
            echo $epercentage;                                       
    }else{
        echo "false";
    }


    Session::push('level',$level);

    $getsession = [  'qid' => $getidvalue,  'answer' => $getanswervalue];

    Session::push('answer', $getsession);
}   

我的问题是我在简单分页中无法获得第二个条件的视图,我们可以跳过这样的问题吗?

0 个答案:

没有答案