I’m a student learning SQL and PHP, I have been set a task to create a student feedback form using PHP and mySQLi, and im really stuck at getting my head around how to design the database for the project!
I’m creating a system where users can log into a web page, and if the user is a student, they can see a page to leave feedback for each lesson had for each module (class). If they are a tutor, when they log in they can view the feedback, add modules with the amount of lessons there will be and add student accounts.
I don’t understand which would be the best way to create the tables for the database, especially as I understand you cannot put a table within a table, I was going to have a table for modules and within each module would be a table for each lesson which is a table holding each item of feedback and a few other variables such as an additional message.
How can I structure my database without creating hundreds of tables and trying to link them together, as I’m new to SQL and this seems a very long winded untidy way.
I’ve been trying to get my head around databases for days now and I just don’t know what to do!
You shouldn’t need hundreds of tables! You will, however, need to link them using primary keys. This is the essence of SQL, and newbie or not, that’s exactly what you need to learn.
In essence, you are putting a table inside a table, but you link them together by matching keys:
When you query these tables, you connect them together in your SELECT statement:
The rows you get back are a combination of the two tables, connecting (or JOINing) the two together wherever the primary key (in this case, student_id) is equal in both tables.