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

asdasdsa's avatar

Compare "correct" and "wrong" from and display result in a progress bar.

Hi!

So I'm keeping track of on how "hard" questions are in a quiz application I have. But I would like to display a progress bar for admins to they can see if a question is overrepresented in some way.

So this thread is for two problems. First group "correct" and "wrong" for all questions in a specific quiz group. And then for a specific question. Hope this makes sense =)

The database looks like this:

id user_id stack_id question_id answer created_at updated_at
1   1   1   3   wrong   2017-09-28 20:51:39 2017-09-28 20:51:39
2   1   1   4   correct 2017-09-28 20:52:18 2017-09-28 20:52:18
3   1   1   5   wrong   2017-09-28 20:54:24 2017-09-28 20:54:24
4   1   1   1   wrong   2017-09-28 21:05:49 2017-09-28 21:05:49
5   1   1   1   correct 2017-09-28 21:07:41 2017-09-28 21:07:41
6   1   1   3   correct 2017-09-28 21:07:46 2017-09-28 21:07:46
7   1   1   4   correct 2017-09-28 21:07:50 2017-09-28 21:07:50
8   1   1   1   wrong   2017-09-28 21:09:32 2017-09-28 21:09:32
9   1   1   3   wrong   2017-09-28 21:09:35 2017-09-28 21:09:35

So for the first problem. I think grabbing all answers with stack_id, then maybe group by correct/wrong? And display the result on a progress bar?

<progress class="progress is-success is-small" value="#" max="#"></progress>

The second problem is for a specific question. Maybe do the same but with question_id?

Doing this will improve for admins and moderators to follow what questions and what "group" of questions that seems to be problematic for the students.

Hope this makes sense, I have not been able to solve it myself!

I have got things working with ordinary SQL, but cannot figure out on how to implement it

Example:

SELECT COUNT(*), answer FROM
`answers`
where `stack_id` = 1
GROUP BY answer
0 likes
1 reply
asdasdsa's avatar

So I'm being able to fetch ass "answers" from the model

$subjects = Subject::with('stack.question', 'stack.progress')->get();

and the model

    public function answers(){
        return $this->hasMany(Answers::class);
    }

    public function progress(){
        return $this->answers();
    }

But I'm not able to count or groupBy

Please or to participate in this conversation.