dth42345 2012-12-02 13:19
浏览 75
已采纳

在数据库中表示具有输入依赖性的径向

I would just like to ask how to best represent in database schema the forms with radial button (Y/N) that if yes, would have an input field. Like "Are you taking medications right now?" (o) Yes or (o) No. If yes is selected, the input field would become available and they have to write it down. Currently I have this very simple schema:

tblUser
-----------
user_id

tblAnswers
--------------
answer_id
user_id
question_id
answer


tblquestions
----------------
question_id
question_text

I think the schema I have right now is fine for most things: multiple checkboxes as an answer, radial buttons, etc. But for radial buttons with dependent input field, I'm not sure. I would like to have it straightforward and simple by the way...I only have 1 survey per 1 user. And the questions won't change for a long long time; perhaps even never. Then again, maybe my current schema would work for radial with input dependency...instead of Yes as an answer, I'll have the input field value instead? So in tblanswer I could have an answer like Stress pills (instead of Yes) or No. Would that be acceptable? Or is that a bad idea? Any help would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • duanduan1993 2012-12-05 12:47
    关注

    I will offer a solution to the radio button, i will not adress your table structure as it is irrelevant for this answer, but i'll leave a tip here: forget normalization rules, they are impractical in most cases.

    Now, on to your problem, you are describing 3 possible outcomes (YES, NO, and TEXT) but in fact you have only 2 (NO and TEXT) as the existence of TEXT means already the answer was YES.

    So, what you should do is prepare your inputs to send "null" or "text", use some javascript to show/hide a text input and get some logic behind the INSERT query to detect if it should save the input as null (for radio off) or as $_POST['foo'] (for radio on).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 经gamit解算的cors站数据再经globk网平差得到的坐标做形变分析
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式