Creating good database structure
===

#Few words about my idea
Working on some web based, education project. Creating question-answer system for this project. There is some logical difficulties that I can't figure out:

There are teachers and students between users. Every student selects some course during signup. 

I have 5 tables: `users`, `courses`, `lessons`, `questions`, `answers`.

There might be 2 types of questions:

 1. `User` based. For ex, when teacher wants to send questions to specific users and vise-versa (users may post question to teachers too).

 2. `Course-lesson` combination based. For ex, teacher wants to post questions to all course listeners based on lesson, they are currently in.

#What I've done

I've created `questions from-to` (qft) table

    CREATE TABLE `questions from-to` (
      `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `qid` int(11) unsigned NOT NULL,
      `from_uid` int(11) unsigned NOT NULL,
      `to_uid` int(11) unsigned NOT NULL,
      PRIMARY KEY (`id`),
      KEY `qft.from_uid_users.id` (`from_uid`),
      KEY `qft.to_uid_users.id` (`to_uid`),
      KEY `qft.qid_qe.id` (`qid`),
      CONSTRAINT `qft.from_uid_users.id` FOREIGN KEY (`from_uid`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
      CONSTRAINT `qft.qid_qe.id` FOREIGN KEY (`qid`) REFERENCES `questions_and_exercises` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
      CONSTRAINT `qft.to_uid_users.id` FOREIGN KEY (`to_uid`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8

Which looks like that

http://i.stack.imgur.com/iMQ9O.png

 - `qid` - is question id, connects this table with `questions`, based
   on `id`
 - `from_uid` - from user id (question sender id), connects this table with `users`, based
   on `id`
 - `to_uid` - to user id (question receiver id), connects this table with `users`, based
   on `id`

So I tried to create some universal solution for both: 

 - students and teacher so they can post questions to each others. **ok**

 - teacher can post to some users specific questions. **ok**

BUT there is a problem

#The problem is  

What if, teacher wants to post question for all course listeners? I already have `user-course` relationship table, but, currently I need to add one-by-one user id's into `questions from-to` table so they can receive questions. I have no idea, how can I design this table for both situations: for "mass questioning" based on `course-lesson` combination and for "user-user" type question posting (teacher sends questions to specific students and vise-versa)

Any suggestions? Please explain your idea. Thx in advance