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 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿