dongzhuo1498 2018-06-02 11:29
浏览 38
已采纳

Laravel 5.4:单击按钮后随机显示多行

I have a table questions and a table question_options in my database and I want when the user clicks on the button play he will see a random question from the database to answer it, then press the next button and an another question must appear to him, although each question should appear in a 30 seconds. my tables :

Schema::create('questions', function (Blueprint $table) {
    $table->increments('id');
    $table->string('question_text');
    $table->integer('points');
    $table->integer('temps_reponse');

    $table->integer('categories_id')->unsigned();
    $table->foreign('categories_id')->references('id')->on('categories');

    $table->integer('type_id')->unsigned();
    $table->foreign('type_id')->references('id')->on('types');

    $table->timestamps();

});

Schema::create('question_options', function (Blueprint $table) {
    $table->increments('id');
    $table->string('option_one');
    $table->string('option_two');
    $table->string('option_three');
    $table->string('correcte');

    $table->integer('question_id')->unsigned()->nullable();
    $table->foreign('question_id')->references('id')->on('questions');

    $table->timestamps();

});

Can anyone tell me how to solve this. Any help would be really appreciated, thanks much

  • 写回答

1条回答 默认 最新

  • duanquan1243 2018-06-02 15:23
    关注
    $randomQuestion = DB::table('questions')
                    ->inRandomOrder()
                    ->get();
    

    See Laravel documentation

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计