Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Asser90's avatar

Quiz - Get unique questions based on inputs - Point in right direction.

Hi there. Its almost against my principles to ask on discussionboards whats probably allready answered somewhere out the great www. However this time google and a few more searchengines could not help me.

I'm currently (first time using laravel) trying to develop a quiz system. The quizzes works the way that it has to generate a quiz based on parameters. Either it has to be a quiztype 1 - 2 or 3. Each individual question is 1 Question and 4 Postulates which you can either answer yes or no to. The quiz is meant to show only 1 question per page, with at next and prev button and questions number 1-many(depends on how many there is - but like a pagination) Everytime you go to next question i would like to save the answer so that if you go back it would still be there, and if you close the browser, you would be able to continue another time.

Now that you know what im aiming for i shall continue.

As of i now i have following tables in my MySql db.

FP_Test: | id(auto) | test_id(varchar50) | user_id(int) | submitted(bool) |

This table is the one used for "generating" a quiz when user clicks the button. Start quiz.

FP_Questions: | id(auto) | question(text) | cat_id(int) | level(int) |

This is the table that holds all questions and has many postulates.

FP_Postulates: | id(auto) | q_id(int) | postulate(text) | postulate_tf(bool) |

This is all the postulates that belongs to question q_id, truefalse is done by bool. Theres 4 postulates for every question.

FP_answer: | id(auto) | answer(tinyint) | q_id(varchar50) | postulate_id(int) | score(int) |

This table is used when people answer, it goes in here. This means there will be 4 fp_answer foreach question.

So right now i have form button which triggers this:

    public function create_prove_test()
    {

        $user = Auth::user()->id;

        $test_id = str_random(20);
        $user_id = $user;
        $q_id = 0;
        $submitted = 0;

        $newtest = new FP_test;

        $newtest->test_id = $test_id;
        $newtest->user_id = $user_id;
        $newtest->submitted = $submitted;
        $newtest->save();

        return Redirect::to('/prove/forprove/' . $test_id); //this redirects to the quiz executer.
    }

Now my struggle is. How do i pick 45 random and unique questions and display them on the /prove/forprove/' . $test_id?

I know how to do a normal fetch, but im unsure how i get it to not pick the same questions 2 times and how to do the pagination with a save when clicking next and prev.

What makes my head hurt too is that i would like people to be able to continue if they stop, so i'm thinking of a way to either load the questions 1 at a time or insert all quiz_questions in a db so that when you start a test you insert 45 new lines into the table. But i kinda think that would kill it in the end?

Can someone point me in the right direction? - And if someone thinks of a better way to achiev my goal i can deal with that too.

Sorry for the long post. - Thanks in advance!

0 likes
0 replies

Please or to participate in this conversation.