Hello Codeigniter Community.
I am just new to Codeigniter. And I am facing a small challenge now. Would you help me solve this?
Here is my problem:
I am making a questionaire system. The user should be able to create a questionaire, add questions and add choices to it.
The question will go to "question" table and the choices will go to the "choices" table.
I did this by saving the question first, get the inserted id, then insert each choice.
Now, I want to retrieve all the questions connected to a questionaire. I did this by joining the question table and the choices table.
I want my questions to look like this:
EXAMPLE
-------------------------------
1. How's your mama?
[] Happy
[] Not Happy
-------------------------------------
Now my question is:
How can I display the question once, then display all the choices below? Like the provided example above.
Here's what I have tried so far:
Then I call that method in a controller. Then I pass the result into a view.
Now, when I do a foreach loop, the result I get, compared to the given example above:
How's your mama
[] Happy
How's your mama
[] Not Happy
It shows the quesiton as many times as the choices. So if I have 5 choices, it will also display the question 5 times.
Would you help me with this? I hope I explained myself well. Thanks in advance. Any help/suggestion would be much appreciated.
I am just new to Codeigniter. And I am facing a small challenge now. Would you help me solve this?
Here is my problem:
I am making a questionaire system. The user should be able to create a questionaire, add questions and add choices to it.
The question will go to "question" table and the choices will go to the "choices" table.
I did this by saving the question first, get the inserted id, then insert each choice.
Now, I want to retrieve all the questions connected to a questionaire. I did this by joining the question table and the choices table.
I want my questions to look like this:
EXAMPLE
-------------------------------
1. How's your mama?
[] Happy
[] Not Happy
-------------------------------------
Now my question is:
How can I display the question once, then display all the choices below? Like the provided example above.
Here's what I have tried so far:
Code:
public function select_question_choices($survey_id)
{
$this->db->select('question.id as question_id');
$this->db->select('question.title as question_title');
$this->db->select('choices.title as choices_title');
$this->db->from('question');
$this->db->join('choices', 'question.id = choices.question_id');
$this->db->where(['question.survey_id' => $survey_id]);
$query = $this->db->get();
return $query->result_array();
}Then I call that method in a controller. Then I pass the result into a view.
Now, when I do a foreach loop, the result I get, compared to the given example above:
How's your mama
[] Happy
How's your mama
[] Not Happy
It shows the quesiton as many times as the choices. So if I have 5 choices, it will also display the question 5 times.
Would you help me with this? I hope I explained myself well. Thanks in advance. Any help/suggestion would be much appreciated.