Simple Conditional Comparison with Text ResultIntroductionConditional comparisons are one of the most versatile functions in MGI. The conditional tags allow you to perform logical comparisons between two values and display a result based on whether the comparison is true or false. The mgiInlineIf tag is used when there is only one conditional comparison and the result is a string of text. The mgiIf tag is used when there are multiple conditional comparisons or the result of the comparison contains code in addition to a string of text (e.g., MGI tags). The mgiSwitch tag is used when there are multiple comparisons and multiple matching results. Text, HTML tags, and MGI tags may be included in the result of an mgiIf or mgiSwitch comparison. See the advanced tutorials for examples of mgiIf and mgiSwitch. More often than not, one of the values in a conditional comparison is embedded in the tag's parameter from another source (page or site variables, post arguments, path arguments, etc.). Read more about embedding. In this example, a conditional comparisons is used to determine a passing or failing grade from an online quiz. The example consists of a hard-coded quiz form and a grade processing page. On the processing page, the numeric quiz score is tabulated from the quiz answers using an mgiMath tag and the total quiz score is compared with a the passing grade to determine which text displays. MGI TagsSteps
Step 1: Create a quiz form.
<FORM action="grade.mgi" method="post"> <H2><CENTER>Grade 1 Quiz</CENTER></H2> <P><CENTER><FONT COLOR="#006600" SIZE="-1"> <mgiDate></FONT></CENTER></P> <P>Student Name: <INPUT NAME="StudentName" TYPE="text" SIZE="30"></P> <P>1. What is the result of 1 + 2?</P> <P><INPUT TYPE="radio" VALUE="0" NAME="Q1">1<BR> <INPUT TYPE="radio" VALUE="0" NAME="Q1">2<BR> <INPUT TYPE="radio" VALUE="20" NAME="Q1">3<BR> <INPUT TYPE="radio" VALUE="0" NAME="Q1">4</P> <P>2. What noise does a cow make?</P> <P><INPUT TYPE="radio" VALUE="0" NAME="Q2">oink<BR> <INPUT TYPE="radio" VALUE="20" NAME="Q2">moo<BR> <INPUT TYPE="radio" VALUE="0" NAME="Q2">bark<BR> <INPUT TYPE="radio" VALUE="0" NAME="Q2">meow</P> <P>3. <FONT COLOR="#ff0000"> What color is this sentence?</FONT></P> <P><INPUT TYPE="radio" VALUE="0" NAME="Q3">green<BR> <INPUT TYPE="radio" VALUE="0" NAME="Q3">blue<BR> <INPUT TYPE="radio" VALUE="20" NAME="Q3">red<BR> <INPUT TYPE="radio" VALUE="0" NAME="Q3">white</P> <P>4. What holiday is on December 25th?</P> <P><INPUT TYPE="radio" VALUE="20" NAME="Q4">Christmas<BR> <INPUT TYPE="radio" VALUE="0" NAME="Q4">Halloween<BR> <INPUT TYPE="radio" VALUE="0" NAME="Q4">Thanksgiving<BR> <INPUT TYPE="radio" VALUE="0" NAME="Q4">Easter</P> <P>5. What is your teacher's name?</P> <P><INPUT TYPE="radio" VALUE="0" NAME="Q5">Mrs. Smith<BR> <INPUT TYPE="radio" VALUE="0" NAME="Q5">Mrs. Arnold<BR> <INPUT TYPE="radio" VALUE="0" NAME="Q5">Ms. Pepperdyne<BR> <INPUT TYPE="radio" VALUE="20" NAME="Q5">Mr. Clemmons</P> <P><INPUT NAME="name" TYPE="submit" VALUE="Submit Quiz for Grading"> <INPUT NAME="name" TYPE="reset" VALUE="Reset Quiz Answers"> </FORM> Step 2: Create a grade processing page and open it in a text editor.
Step 3: Insert the mgiInlineIf tag.
<H2><CENTER>Grade 1 Quiz Score</CENTER></H2> <P><CENTER><FONT COLOR="#006600" SIZE="-1"> <mgiDate></FONT></CENTER></P> <mgiSet name="QuizScore"> <mgiMath resultPrecision="0"> <mgiPostArgument name="Q1">+<mgiPostArgument name="Q2">+ <mgiPostArgument name="Q3">+<mgiPostArgument name="Q4">+ <mgiPostArgument name="Q5"> </mgiMath> </mgiSet> <CENTER> <P><mgiPostArgument name="StudentName">, your quiz score is <mgiGet name="QuizScore">.</P> <P> <mgiInlineIf lhs={mgiGet name="QuizScore"} relationship="greaterThanOrEqualTo" rhs="60" then="Congratulations, you pass and receive 1 gold quiz star." else="You did not pass. Please see the teacher."> </P> </CENTER> Step 4: Save the grade processing page.
Step 5: FTP the quiz form and grade processing page to the web server running MGI.
Step 6: View the quiz form in a web browser and take the quiz.
|