better way to show grade in php
Hello to all,
I am new to this forum. I have written following program in php. Following program shows grades according to your percentage. I want to know, is there any better way to show grade in php? Please help me.
I have written following code for your understanding.
Code:
if ( Grade >= 95 ) {
echo "A";
} elseif ( Grade >= 85 ) {
echo "B";
} elseif ( Grade >= 75 ) {
echo "C";
} else {
echo "Fail."
}
Re: better way to show grade in php
As per my knowledge you are using one of the simplest code to show grade according to percentage. It is one of the efficient and easy to understand code. In other code you have you have to use either switch case or you can use if else statement to show grade according to percentage. Just use this code in your program and run your program.
Re: better way to show grade in php
Hey there is other way through which you can show grade of student according to his percentage. In other way you have to convert Grade into value so that it can be used in array. If you don't know how to do this then use following code.
Code:
Gradei = (int)Grade / 11;
Graden= array('90' => 'A+', '80' => 'A', '70' => B, ..... );
Re: better way to show grade in php
As per my information the code you have written is very simple one but if you want more advanced and more fast execution then you can use following code. It is very simple program. In this program I have use switch statement.
Gradei = (int)Grades / 10;
case 10:
case 9:
Gradei = 'A';
break;
case 8:
Gradei = 'B';
break;
case 7:
Gradei = 'C';
break;
default:
GradeName = 'Failed';
}
echo GradeName;
Re: better way to show grade in php
Hey there is no need to use switch statement or any other case. You can easily do this using simple if statement. I have written one simple code for you just try to understand it. It is very simple. In following code I have use one function called intGradeToStrGrade()
Code:
function intGradeToStrGrade(Grades) {
if (Grades >= 95) return "A";
if (Grades >= 85) return "B";
...
}
Re: better way to show grade in php
Quote:
Originally Posted by
Zecho
Hey there is no need to use switch statement or any other case. You can easily do this using simple if statement. I have written one simple code for you just try to understand it. It is very simple. In following code I have use one function called intGradeToStrGrade()
Code:
function intGradeToStrGrade(Grades) {
if (Grades >= 95) return "A";
if (Grades >= 85) return "B";
...
}
hello.. here is my form,
<form id="form1" name="form1" method="post" action="">
<label for="mark"></label>
<label for="Submit"></label>
<table width="421" height="150" border="0" align="center">
<tr>
<td width="112">Mark </td>
<td width="9">:</td>
<td width="278"><input type="text" name="mark" id="mark" /></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="Submit" id="Submit" value="Submit"/></td>
</tr>
</table>
</form>
how to call that function?