In general, there is a table "question" (id, cid - category, vok - the correct answer is from 1 to 4), to it is a table "answer" (id, pid, title), for each question there are 4 answers. When we select these 4 responses, they have an id like in the table. How to make them have an id from 1 to 4? So that you can check the value of radio with the value of vok.

Well, or just tell us how to build QUIZ with a random sample of questions from a category and a random spread of answers. And in detail, how to verify select with the correct answer.

  • one
    And why not to store the answer in the vok id from the table? - yozh
  • Simply adding a new question from the admin panel is so arranged that we do not know in advance the id of the future answer. Or know? - chuikoff
  • Well, either when you add a question you don’t know anything about the answer (you know the number, for example), or you can get the id in the same query where the title is. - Sh4dow

2 answers 2

I think that the vok column (such as yes / no) should not be in the “question” table, but in the “answer” table. This, among other things, will allow you to have questions with several correct answers.

    /* таблицы которые хранят общую информацию о вопросах */ // таблица где хранятся доступные вопросы create table question_def (question_id, question_title, is_multy_answer_allowed); // ^^ здесь последнее поле устанавливает допускает ли вопрос множественные ответы // таблица где хранятся данные о допустимых ответах create table answer_def (answer_id, answer_category_id); create table answer_value_def (id, answer_order, is_answer, value); // ^^ здесь order отвечает за порядок отображения и является частью PK вместе с id // и имеет значение 1-4 для ваших radio // is_answer поле определяет правильный это ответ или нет (напр 4 записи и только у одной стоит 1, она и есть правильным ответом на этот вопрос) /* таблицы которые хранят результаты */ // таблица где хранятся данные об ответах на вопросы create table question (question_id, ...); create answer (answer_id, question_id, player_id, ...); create answer_value (answer_id, question_id, order_id, valu 

    e);

    ps if you always have only 4 options, then it’s worth replacing the *_value with 4 fields in question_def, answer_def tables question_def, answer_def (in other tables it’s similar to