A student chooses 4 modules out of 9 every year to undertake as part of his course.
I will create a table in my db which has two fields - student_id and module_title.
I would like to create a form which gives the student 4 drop down boxes which are popluated from a database table (which I can code).
Question is, how can i write a script to automatically insert a new record 4 different times into my database for a particular student?
Many thanks for your advice.
Abi (newbie programmer)
Some advice needed for code
Moderator: General Moderators
- abionifade
- Forum Commoner
- Posts: 34
- Joined: Thu Apr 18, 2002 5:32 pm
- abionifade
- Forum Commoner
- Posts: 34
- Joined: Thu Apr 18, 2002 5:32 pm
hiya guys,
the suggestion on making 4 insert statements sounds good if i could get my head around it.
What need to happen is for the student_id field to be inserted 4 times in the table along with the chosen module_title. So in thoery, when i look at the database, i should see 4 entries for a student, but each having a different module_title.
What im confused with is sending the form variables to the php script to then insert 4 times into the same column name but new record each time...
Any ideas?
the suggestion on making 4 insert statements sounds good if i could get my head around it.
What need to happen is for the student_id field to be inserted 4 times in the table along with the chosen module_title. So in thoery, when i look at the database, i should see 4 entries for a student, but each having a different module_title.
What im confused with is sending the form variables to the php script to then insert 4 times into the same column name but new record each time...
Any ideas?
Just use a few selects or if you wanna be really clever do multiple selects you could do <select name="choice1"><option value="option1">Option1</option></select> etc... and then make sure they haven't selected the same one twice and then do:
Code: Select all
<?php
mysql_query("INSERT INTO tablename ('$studentid','$Choice1')");
mysql_query("INSERT INTO tablename ('$studentid','$Choice2')");
mysql_query("INSERT INTO tablename ('$studentid','$Choice3')");
mysql_query("INSERT INTO tablename ('$studentid','$Choice4')");
?>- abionifade
- Forum Commoner
- Posts: 34
- Joined: Thu Apr 18, 2002 5:32 pm
Hi and thanks for getting back to me with a great idea.
Preferably, i would like the module_title and stundent_id field to be the only two within the table.
Your example inserts student_id field with choice_1, choice_2 etc.
Is there anyway i can insert 4 individual entries each uniquely identified by the student_id field?
the table contents would look like this
ch150 Computing
ch150 Maths
ch150 Science
ch150 Physics
Im basically confused as to how to create a script to take 4 possible module_titles and assign them to a student_id like above.
Any ideas?
many thanks
Preferably, i would like the module_title and stundent_id field to be the only two within the table.
Your example inserts student_id field with choice_1, choice_2 etc.
Is there anyway i can insert 4 individual entries each uniquely identified by the student_id field?
the table contents would look like this
ch150 Computing
ch150 Maths
ch150 Science
ch150 Physics
Im basically confused as to how to create a script to take 4 possible module_titles and assign them to a student_id like above.
Any ideas?
many thanks