Ben bir sigorta teklif sistemi yapı ve sormak için bir dizi soru var ediyorum. Benim sorular bir tablo (questionsTable) saklanır, benim cevaplar (alıntı bakın veya başka bir soru soracak olsun, yani) cevapları masasına (answersTable) ve soru / cevap eylem saklanır eylemler tablosunda depolanan (actionsTable) .
İşte bazı örnek veriler bulunuyor
questionsTable
questionId | questionDescription
1 | What percentage of the roof is flat?
2 | Please provide details of the roof construction:
3 | How many rooms does the building have?
answersTable
answerId | questionId | answerValue
1 | 1 | < 50%
2 | 1 | > 50%
3 | 2 | freeForm
4 | 3 | 1
5 | 3 | 2
6 | 3 | 3
7 | 3 | 3+
actionsTable
actionId | answerId | action
1 | 2 | 2
2 | 6 | refer
3 | 7 | decline
The way the tables link is this: Each question has answers, selectable from the database certain answers carry certain actions - ask another question, or decline the quote. If they are to ask another question, the id of the question is stored in the action field.
Eğer 1. soruya '>% 50' cevap Yani temelde, 'çatı yüzde kaçı düz?' Eğer cevap soruyu 2. verilmiş olsun.
Böylece 'üst düzey' bir soru seti bana veriyorsun - Benim soru nasıl kimliği 'actionsTable' dan 'eylem' değerlerden herhangi birine eşit değildir 'questionsTable' tüm soruları seçebilirsiniz, nedir?
Ben 'actionsTable' tüm sayısal değerleri seçmek için iki MySQL sorguları, 1 kullanarak PHP sadece bu yapabileceğini biliyorum, daha sonra başka bir soru seçin
'SELECT questionDescription
FROM questionsTable
WHERE questionsTable.questionId != 'this' AND questionsTable.questionId != 'this', etc
Bu veritabanı tasarımı normalize edilmesi için değil, aynı zamanda dinamik, örneğin, yönetim ekibi kaldırmak / sorular, cevaplar ve eylemler eklemek için yönetici sayfalarını kullanabilirsiniz.