I have the following tables:
http://postimg.org/image/7n6ifo3lj/
My code:
public function question_management() { $question_management_crud = new grocery_CRUD(); $question_management_crud->set_theme('datatables'); $question_management_crud->set_table('question'); $question_management_crud->display_as('question_id','Question Text'); $question_management_crud->set_subject('Question'); $question_management_crud->set_relation('question_id', 'option', 'option_text'); $output = $question_management_crud->render(); $this->_table_output($output); }
I want a question page that shows all the options associated with a question. I would also like it when they click edit or "Add Question" they can create options for the question on the same page.
Example Question: Do you like fruit?
Example Options for above question:
Yes,
No,
As you can see the options table has an option_number which says which option comes first, and option text (Yes or No). A very simple survey generator.
On my results, all I see is a list of questions. There is no option information showing per question. What am I doing wrong? And how can I make it so you can create as many options as you want on the question creation form.
Output screenshot:
http://postimg.org/image/44lyxey7z/
SQL for my tables:
-- ----------------------------------------------------- -- Table `survey`.`question` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `survey`.`question` ( `question_id` INT NOT NULL AUTO_INCREMENT, `question_text` VARCHAR(255) NULL, PRIMARY KEY (`question_id`)) ENGINE = InnoDB; -- ----------------------------------------------------- -- Table `survey`.`option` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `survey`.`option` ( `option_id` INT NOT NULL AUTO_INCREMENT, `question_id` INT NOT NULL, `option_number` INT NOT NULL, `option_text` TEXT NULL, INDEX `fk_option_question1_idx` (`question_id` ASC), PRIMARY KEY (`option_id`), UNIQUE INDEX `uk_question_option_number_key` (`question_id` ASC, `option_number` ASC), CONSTRAINT `fk_option_question1` FOREIGN KEY (`question_id`) REFERENCES `survey`.`question` (`question_id`) ON DELETE NO ACTION ON UPDATE NO ACTION) ENGINE = InnoDB;
Thank you so much for the help in advanced. I have been stuck on this issue will no luck finding the answer.