What I want :
- To get a
grade of what the user answered in the database, if one exists, and get an estimate of this answer.
What I have :
- I have tables
3 , short_answer , sa_sa_answer , short_answer_answer . - Now the
short_answer table has a question, and each question has many answers located in the short_answer_answer table, and the class is also included there, the question can have 1 or more answers.
What is my code:
controller
foreach($sa_question_id as $key => $value){ $sa = ShortAnswer::with('answers')->find($sa_question_id[$key]); $possible_answers = []; foreach($sa->answers as $possible_answer){ $possible_answers[] .= strtolower($possible_answer->answer); } if(in_array(strtolower($sa_answer[$key]), $possible_answers)){ $grade = ShortAnswerAnswer::where('answer', $sa_answer[$key])->get(); echo "plus +1. Grade is: " . $grade->grade . "<br>"; } }
The problem is this:
I just get the answer where the answer is equal to the user's response. But what if I have TWO strong> the same answer and a different grade and obviously a different question. He may choose the wrong one.
Note: I am using Laravel5.1
Update: Table Structure
short_answer
- name
- question
sa_sa_answer
- short_answer_id
- short_answer_answer_id
short_answer_answer
- answer
- grade
Refresh
I already solved this problem, but no one received the generosity, but if you could answer this question , I can give you the generosity plus 2 , and I really need additional help. This is also related to this issue. Now the bounty will disappear after 3 days.
php eloquent laravel-5
Jonjie
source share