html if statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
trtcom1
Forum Newbie
Posts: 14
Joined: Mon Dec 01, 2008 10:51 am

html if statement

Post 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.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: html if statement

Post 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
trtcom1
Forum Newbie
Posts: 14
Joined: Mon Dec 01, 2008 10:51 am

Re: html if statement

Post 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.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: html if statement

Post 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
Post Reply