0

I have students, student_subject, subjects and results tables.

Students Table

| id | name  |
|----|-------|
| 1  | John  |
| 2  | Sara  |
| 3  | Smith |

Subjects Table

| id | name        |
|----|-------------|
| 1  | Science     |
| 2  | Mathematics |
| 3  | English     |

Student_subject Table

| id | student_id | subject_id |
|----|------------|------------|
| 1  | 1          | 1          |
| 2  | 1          | 2          |
| 3  | 2          | 1          |
| 4  | 3          | 1          |

Results Table

| id | student_subject_id | result |
|----|--------------------|--------|
| 1  | 1                  | 45     |
| 2  | 2                  | 25     |
| 3  | 3                  | 65     |
| 4  | 4                  | 45     |

There are separate forms to insert students (with selecting subjects), subjects and results. I got a problem creating the form to add results for a student.

The form consists of form inputs listing down all the subjects of the student to enter results. For a specific student, the form to insert results may look like this(after looping the students subjects). The name attribute contains the Student_subject table id value. I add the name to this value because In the database I need to have reference for the student_subject table in the database.

<form>
  <input type="text" class="form-control" name="1" required>
  <input type="text" class="form-control" name="2" required>
</form>

I want to know this approach is correct or wrong to add results to students? If not what are the changes I have to do in database and forms.

camille
  • 278
  • 1
  • 2
  • 20
  • 1
    The input name is for the name of the input, not the value. – Greg Schmidt Jan 04 '20 at 16:33
  • Greg Schmidt, If not how can I have a reference in the database? – camille Jan 04 '20 at 16:37
  • 1
    You need to put the ids in hidden inputs with the values set to the IDs, and you need to name all the inputs so that they come through as arrays, like in [this answer](https://stackoverflow.com/a/3314578/4987673). – Greg Schmidt Jan 04 '20 at 16:42
  • I didn't understand. can you clarify a little bit. – camille Jan 04 '20 at 16:53
  • 1
    ``. Replace `[0]` with `[1]` and so on for the second and subsequent subjects. – Greg Schmidt Jan 04 '20 at 16:58
  • 2
    I'm not sure what benefit you get from having a separate results table; I would include the result column in the student_subject table, defaulting to null when the result isn't known yet. – Greg Schmidt Jan 04 '20 at 17:00

0 Answers0