Page 1 of 1

html if statement

Posted: Tue Aug 25, 2009 4:40 pm
by trtcom1
Hi there,
I have 3 tables:
Student (studentNum,firstName,lastName,CourseName),
course (courseID,courseTotalCapacity),
course_allocation (studentNum,courseID).
I have 3 courses, MATHS=101,BIOLOGY=102,CHEMISTRY=103.
My form has the following:

Code: Select all

 
<SELECT NAME="CourseName">
<OPTION VALUE="MATHS">MATHS</OPTION>
<OPTION VALUE="BIOLOGY">BIOLOGY</OPTION>
<OPTION VALUE="CHEMISTRY">CHEMISTRY</OPTION>
</SELECT></td></tr>
 
<SELECT NAME="courseID">
<OPTION VALUE="101">MATHS=101</OPTION>
<OPTION VALUE="102">BIOLOGY=102</OPTION>
<OPTION VALUE="103">CHEMISTRY=103</OPTION>
</SELECT>
I would like to have some kind of a if statement, that if the user chooses the CourseName MATHS, then the courseID 101 is entered to the course and course_allocation tables and MATHS entered to the CourseName table.
As it is the user has to choose MATHS and choose MATHS=101, then click submit.
Any help, please.

Re: html if statement

Posted: Tue Aug 25, 2009 5:17 pm
by Mark Baker
Surely the better database structure is:
Student (studentNum,firstName,lastName)
course (courseID,courseName,courseTotalCapacity)
course_allocation (studentNum,courseID)
with the courseName column moved to the course table where it belongs, and no duplication of course data between the student and course_allocation tables


and only

Code: Select all

 
<SELECT NAME="courseID">
<OPTION VALUE="101">MATHS=101</OPTION>
<OPTION VALUE="102">BIOLOGY=102</OPTION>
<OPTION VALUE="103">CHEMISTRY=103</OPTION>
</SELECT>
 
for the HTML form

That way, you're not forcing the user to enter the same data twice

Re: html if statement

Posted: Wed Aug 26, 2009 2:26 pm
by trtcom1
Thank you very much for your comments and help. This thread can be considered as solved. This is my final solution:
Here the html select:

Code: Select all

<SELECT NAME="courseID">
<OPTION VALUE="101">MATHS</OPTION>
<OPTION VALUE="102">BIOLOGY</OPTION>
<OPTION VALUE="103">CHEMISTRY</OPTION>
</SELECT>
And created a php if-statement:

Code: Select all

if ($courseID =='101')
{
      $CourseName = 'MATHS';
 
      //code for the insert statement
}
 
if ($courseID =='102')
{
      $CourseName = 'BIOLOGY';
 
      //code for the insert statement
}
And it is working fine.
But the same does not work for the update statement.

Re: html if statement

Posted: Wed Aug 26, 2009 4:05 pm
by Mark Baker
You don't need that set of if statements if your table is
course (courseID,courseName,courseTotalCapacity)
You simply read courseName from the database table based on the courseID value

And you don't store the coursename in the user record