How to design database system for a feedback systems? - php

Hi I'm just getting into PHP and MySQL and English is my second language so excuse me while I try to describe my question well.
I'm trying to create a feedback system where students can leave feedbacks about teachers. A student log in pick a subject first, then find a teacher who teaches that subject and can leave feedback of that teacher. All the feedbacks of a teacher can be seen by public(no require login) And the teacher can log in have look at the feedbacks and mark them as read, once a feedback is marked as read it won't be shown publicly again .
The problem I'm having is not about the idea itself or the login system etc, it's about the database structure. Mainly the teachers feedback database, first the teachers are categorised by subjects, then each individual teacher need to store feedbacks, and those feedbacks can be active(not read yet) or inactive (read).
Since I'm new to PHP and MySQL I don't know how to design the database to be effective, let's give a problem as a example "Display the numbers of active feedbacks of a teacher" I can think of few ways to approach this, but can't decide which way is the best.
SOLUTION 1, One massive database to store everything , First it needs to filter the database by the subjects, then filter by the teacher name/id then filter out the inactive one then count up how many active feedbacks are there
SOLUTION 2, give each an individual database, and when the student leave feedback it gets stored directly into an active database for that particular teacher , when the teacher mark it as inactive it will be moved to a different (inactive) database of that teacher, so to find out the numbers of active feedbacks just simply count the number of data in that active database.
SOLUTION 3, combine solution 1 and 2, because each teacher can only teach one subject, so we create big databases for each subject, and for each subject we create an inactive database where we store inactive feedbacks, when a feedback is marked as read it will be transferred to that database. Then to find out numbers of active feedbacks we can filter the subject to find the teacher and just simply count up the numbers of feedbacks that teacher have because all the inactive ones will be at a different database.
I hope I did not confuse you with my description, I would really appreciate if any of you can tell me the most efficient way to build database for this problem in PHP and MySQL. Thanks!
Edit 1: sorry I do mean Tables rather than databases, so the question is whether I should create multiple tables for this problem or stick with one.

You could first have student table and teacher table. In your feedback table you can have columns: student, teacher, comment, time

Its better to have multiple tables,for teachers and students and it would be good if use log in functionality too.mainly make sure that design a over all flow of steps,its doesn't be be good choosing subjects and teachers separately,think it in such a way that as soon as you select subject an subject,the appropriate teacher of that particular subject should be also be selected.Better create an clear flow of implementation.

Related

Database set up for multi-way relationships and form data collecting

I've posted a few questions on here and have gotten very great help and support. I'm still fairly new to programming and I'm putting together what I thought would be a simple website for the company I work at. I apologize in advance for my lengthy post/question, I just want to be thorough and clear in what I'm asking. My question is more of needing some help getting pointed in the right direction of how to get started and some best practices to be aware of. What I'm working on right now is to create a system where a user can submit a questionnaire/online form to inquire about a specific product (in this case it's a hard money loan product). The way I am planning on setting it up is to have a database with multiple tables (users, user_info, loan_app, property) and connect these together by referencing each other. I've read about table joins and I understand them conceptually but I have no idea how to implement in practice. I've had a hard time finding actual examples.
Specifically, this is what I am doing and how I am thinking it should work (correct me if I'm wrong or if there's a better way to do it):
1- the user (aka the borrower) signs in to the website. The user log in system references the user table where things like first name, last name, user name, password and user ID are stored. I have included an "active" column in this table so that when a user logs in the condition for them to get into the website is that the username and password match AND the user is activated. This way we can control on the back end certain user accounts access. I have this part working.
2- when the user registers, they only fill out the information that creates a new record in the "user" table. I have created a second table called "user_info" that will contain other data like home address, phone number email etc. But I need to be able to associate the correct record with right user. This is my first issue to wrap my head around. My thinking behind doing this instead of simply putting all this information in the user table is that for one, I might keep adding to that table and make it very big, and two for security reasons, I would like to keep the information separate. I don't know if this thought process has any merit to it though. Again, that's why I'm posting this here.
3- The user, once logged in, clicks on a button on their home screen/dashboard that will take them to the loan "pre-approval application" form, which is the questionnaire. On this form their basic information will be echoed/posted from the "user_info" table to pre-populate certain fields like first name, last name, email, phone number, address etc. So going back to #2 making sure I can associate the user with the correct record in the "user_info" table is critical. THEN, there are additional fields that the user has to fill out in order to submit the application/questionnaire. These form fields will create a new record in the "loan_app" table. This table will have a loanid column that is the primary key for that table, and an auto generated/randomized 6 or 7 digit loan number (loannum). The loanid will be a hidden value but the loan number will be like a reference number that is associated with the loan for the life of it and used for later accounting and recording purposes internally, whether or not it actually becomes a loan. The loanid, I'm assuming here, is the Foreign key in the "user" table and the userid is the Foreign key in the "loan_app" and "user_info" tables correct? If so, how do I incorporate being able to simultaneously associate all these records when the loan application/questionnaire is submitted? My thought would be write individual php scripts that does each of these things separately then have a "master" php that includes all of those individual ones that is placed as the form action associated with the submit button on the form.
Thanks for taking the time to read through this. I'd really appreciate any advice or reference material that I can read up on to learn more about this stuff. My job has a pretty crazy schedule and I travel a lot so I don't have the time to take actual classes to learn this stuff formally. I'm pretty much doing this as I go.
Also, I'm using MAMP with mysql, not sure if that helps any or not...
The user table's primary key userid can be the primary key of the user_info table as well, since each user will have only one user_info record, right? A foreign key constraint is good to ensure only valid userids get recorded in user_info.
The loan_app table can contain a denormalized relationship from loanid to userid so that each loan application is associated with a user. Again, use an FK constraint for integrity.
Don't include loanid in the user table - that would mean each user has a relationship to a single loan application. You already have the one-to-many relationship you need in the loan_app table.

Best way going about making a 'wish list' feature

I've been racking my brain over this for a few days now, and being fairly new to 'back end' stuff, I haven't managed to come up with a table structure that works. What I'm trying to do is create a wish list feature which allows users to save a course to their profile for later. Originally, I created three fields in my 'users' table, named: 'saved_course1', 'saved_course2' and 'saved_course3'. I then tried to come up with a php/sql code that when a user clicks the wish list button on a courses page, the id of the course is saved to the one of the saved courses fields (providing that it isn't already filled), however someone pointed out to me that this would be an terrible way of doing this and it would mean my db wouldn't be normalised.
So to sum my problem up, I need help with creating a table structure that would allow users to save multiple course id's to their account, then allow me to get the id's of the courses and display them in a table on their profile page. Sorry if this makes no sense, as I'm finding it difficult to put it into words.
That's not so difficult just make this table structure below. Let me know if you don't understand it
Example
User(userid,name,etc)
Courses(coursesid,name,fee, etc)
WhishList(userid,coursesid)
userid is foreign key to User, null not allowed
coursesid is foreign key to Courses, null not allowed
Extract courses for particular user
select * from WhishList join courses on Whishlist.coursesid = Courses.coursesid where WhishList.userid = "USER_ID HERE";

HTML/PHP Storing values in table, saving to database and showing it later

I am new and trying to make a simple website for a project. I have to pages, add and view hobbies. User needs to be able to add 1 or more hobbies and store it in a database and to retrieve it in another page, i have listed what i plan to do below.
How do i make it such that I am able to store multiple hobbies for users in the database?
Using MySQL, HTML, PHP, Dreamweaver
Assume: User has been created, user has been logged in and all user related database coding has been done. More than 1 user exists, all users are to have a few hobbies each.
Database
User table: UserId, Username, HobbyId
Hobby table: HobbyId, HobbyName, HobbyDaysAWeek
1 user can have 0 or more Hobbies.
Add hobby page
dropdownlist (binds list of hobbies from hobby table)
textbox (for user to enter how many days a week he spends engaging in that hobby)
add button (displays value in dropdownlist and textbox in a table)
table (Hobby and daysAWeek will be shown here, with a delete icon to delete it)
submit button(saves hobby & days a week & username into database)
View hobby page
Displays user's hobby & days a week in a table.
Thanks for helping! And please provide simple and bare minimum coding as i am new!
Well, nobody posted an answer but my question was answered in the comments so..
Start by adding a 3rd table with UserId and HobbyId – Dagon
You're storing the relationship between, not a relationship. So think of it like you have two things and you want to remember that they relate. Thus, a table with two columns, one with an identifier of one part, the other with identifier (ID) of the other part. Pull them together with the data about each part, you have information. Hence, you've stored the relationship. It's like metadata, really. It's usually pretty efficient. - Jared Farrish
Thanks guys!

manage user permissions in php

i am creating a marks management system using php & mysqlwhere the concerned faculty will be able to login and enter the marks of the students. i can go with a simple table but the problem is there are 288 different subjects for which marks must be entered. So creating a mysql table with so many subjects does not look good for me. please suggest me the best way to manage user permissions so that only the corresponding faculty will be able to enter marks
This is a fairly big and hairy problem; you do know that, right? It is good you're not regarding security as an after-thought, but I don't think it's security you're asking about.
I spent some time developing an academic management system a few years ago. Some of the design required was fairly involved. As well as subjects and students, we quickly found we needed a class structure so we could say this student was in this subject this term, but wasn't next term. And to say that this teacher taught this class this subject this term, but another teacher taught this other class the same subject this term.
That also meant we had to keep some information about when classes were, which turned into a timetable mechanism. (I won't go into that, though, as it was very involved.) And then we had to keep multiple sorts of marks for a student in a class, which created multiple task types, only one of which was end-of-term exams.
Finally, we abstracted our students and teachers into generic contacts. This allowed a permission system to generalise for editing objects they "owned". It also let us support advanced concepts like a former student returning to teach. And for all contacts to login in various capacities.
Table <Subjects>
List item
SubjectId
SubjectName
SubjectTeacher
.
.
Table <Marks>
SubjectId
Date
Marks
.
.
........... This assumes that you have only one teacher per subject. If you want multiple intructors per subject, remove the SubjectTeacher column from the Subjects table and make two new tables
Table <SubjectInstructor>
SubjectId
IntructorId
Table <Instructor>
InstructorId
InstructorName
.
.
May be you can Divide the table based on the class. but still you may have to face several more problems .you better have the tables .

Relationship with Tables MySQL

I have some small issue with relationships with tables as below:
I have created a login and registration script which has the following
table name: members:
fields: member_id, firstname, lastname, login, password
Now i have made another table with this
table name: phone
fields: member_id, phoneid, name, number, prefix, time,total
I want to make a form whereby a admin can select the name of the client from a drop down list, and then add a record such as the number called, number prefix, total time and the amount for that period.
I dont know how to do this, please help me by creating a script or help me how to go about this.
So all the time a admin makes a form on Client A it gets added to a new row on the phone table, then i will just add a call script on the client side where they can see all the records that they have done.
Thanks please assist.
Regards
Your db design seems fundamentally flawed - the is no association between the members and the phone_numbers tables. Add a FK (member_id) to phone_numbers table.
Regards creating the front-end, there are quite a lot of libraries that have data stores (we use ExtJS), and upon flushing the store you can do the persistence with php.
Hope this helps!

Categories