我有以下數據庫設計的麻煩(爲例子簡化)。它允許人們創建自定義表單,與Google spreadheat表單非常相似。表單生成腳本已完成,包括將答案保存到數據庫。我無法顯示用戶輸入。有很多表的複雜查詢,這可能在一個查詢中?
表形式(各形式是在該表中的行)
form_id | form_name
1 Contact Form
2 BBQ sign up Form
表問題(在表格中的問題)
question_id | form_id | question_name | sorting_order
1 1 Full Name 1
2 1 E-mail address 2
3 1 Subject 3
4 1 Message 4
5 2 Your name 1
6 2 Are you vegetarian? 2
7 2 Beer or wine? 3
表completed_forms(以組答案一起)
complete_id | form_id | timestamp
1 1 1339496914
2 1 1148691493
3 2 1256235334
表(從用戶到特定問題的答案)
answer_id | complete_id | question_id | answer
1 1 1 Barack Obama
2 1 2 [email protected]
3 1 3 Test message
4 1 4 This is a test. Regards, Barack.
5 2 1 Thomas something
6 2 2 [email protected]
7 2 3 Another message
8 2 4 Hey, it's Thomas. This is my message.
9 3 5 Dirk
10 3 6 No, I love meat
11 3 7 Red wine!
我想顯示是用戶輸入的概述,這是因爲名字和列數相當複雜的不同每形式回答 。例如,我想顯示從接觸形式的用戶輸入(form_id:1)如下:
id | timestamp | Full Name | E-mail Address | Subject | Message
1 133949... Barack... [email protected] Test... This is a t...
2 114869... Thomas... [email protected] Anot... Hey, it's T...
而且從form_id 2如下:
id | timestamp | Your name | Are you vegetarian? | Beer or Wine?
3 125623... Dirk No, I love meat Red wine!
是否如果與任何人怎麼可以做到這一點?
非常感謝任何願意花時間照亮這個問題的人!
你想要兩個選擇,一個爲每種類型的? –