|
|
|
รบกวนขอคำแนะนำเรื่องคำนวณเกรดหน่อยครับ อยากได้คำแนะนำเรื่อง code php คำนวณเกรด น้อยกว่า 40 =0 50 |
|
|
|
|
|
|
|
$sumgrade = คำแนน;
if ($value < 50){
$sumgrade =0;
}else
if (($value >= 50) && ($value <60 )){
$sumgrade = 1;
}else
if (($value >= 60) && ($value <70 )){
$sumgrade =2;
}else
if (($value >= 70) && ($value < 80)){
$sumgrade = 3;
}else
$sumgrade = 4;
ประมาณนี้นะ ประยุกต์ดูนะ
|
|
|
|
|
Date :
2009-03-22 11:43:12 |
By :
khunset |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ของผมลองทำแล้วเป็น สคิป ลองนำไปดูนะ ผมว่ามันก็โอเคดี ประมาณว่าใส่คะแนนปล้วเกรดขึ้นเลยอัตโนมัติ
ลองดูครับ Code (PHP)
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#000000">
<tr bordercolor="#333333" bgcolor="#FFFFFF">
<td width="20"><div align="center"><font size="3" face="AngsanaUPC, BrowalliaUPC, CordiaUPC"><strong>ที่</strong></font></div></td>
<td width="70" height="26"> <div align="center"><font size="3" face="AngsanaUPC, BrowalliaUPC, CordiaUPC"><strong>รหัสนักศึกษา</strong></font></div></td>
<td width="165"><div align="center"><font size="3" face="AngsanaUPC, BrowalliaUPC, CordiaUPC"><strong>ชื่อ
สกุล </strong></font></div></td>
<td width="30"><div align="center"><font size="3" face="AngsanaUPC, BrowalliaUPC, CordiaUPC"><strong>Md</strong></font></div></td>
<td width="30"><div align="center"><font size="3" face="AngsanaUPC, BrowalliaUPC, CordiaUPC"><strong>Fn</strong></font></div></td>
<td width="30"><div align="center"><font size="3" face="AngsanaUPC, BrowalliaUPC, CordiaUPC"><strong>Tt</strong></font></div></td>
<td width="30"><div align="center"><font size="3" face="AngsanaUPC, BrowalliaUPC, CordiaUPC"><strong>Gd</strong></font></div></td>
</tr>
</table>
<? $i=0;
while ($i<20){
?>
<table border="1" cellpadding="0" cellspacing="0">
<tr>
<td width="20" height="20" align="center"> <font face="AngsanaUPC, BrowalliaUPC, CordiaUPC">
<?echo $i+1 ;?>
<input type="hidden" name="i2" value="<? echo $i ;?>">
</font></td>
<td width="70" height="20"> <div align="center"> <font face="AngsanaUPC, BrowalliaUPC, CordiaUPC">
<? echo $id_no;?>
</font></div></td>
<td width="165" height="20"> <font face="AngsanaUPC, BrowalliaUPC, CordiaUPC">
<?echo "$pname $name";?>
</font></td>
<td width="30"><div align="center"> <font face="AngsanaUPC, BrowalliaUPC, CordiaUPC">
<input name="t1" type="text" id="t1[" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" size="1" maxlength="2" style="width:20px;border:none;text-align:center;" />
</font></div></td>
<td width="30"><div align="center"> <font face="AngsanaUPC, BrowalliaUPC, CordiaUPC">
<input name="t2" type="text" id="t2" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" size="1" maxlength="2" style="width:20px;border:none;text-align:center; "/>
</font></div></td>
<td width="30"><div align="center"> <font face="AngsanaUPC, BrowalliaUPC, CordiaUPC">
<input name="t3" type="text" id="t3" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" size="1" maxlength="3" style="width:20px;border:none;text-align:center; "/>
</font></div></td>
<td width="30"><div align="center"> <font face="AngsanaUPC, BrowalliaUPC, CordiaUPC">
<input name="t4" type="text" id="t4[$a]" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" size="1" style="width:20px;border:none; text-align:center;"/>
</font></div></td>
</tr>
</table>
<font size="2"> </font>
<? $i++; } ?>
<font size="2"> </font><font size="2">
<script language="javascript">
var obj= document.all;
function sum(){
for (var a=0; a<100 ;a++){
obj.t3[a].value=parseInt(obj.t1[a].value)+parseInt(obj.t2[a].value);
if ((!obj.t1[a].value)||(!obj.t2[a].value))
{
obj.t3[a].value='-';
obj.t4[a].value='-';
}
else if (obj.t3[a].value>100)
{
obj.t4[a].value='Error';
}
else if ((obj.t3[a].value>=obj.a1.value)||(obj.t3[a].value==100))
{
obj.t4[a].value='A';
}
else if ((obj.t3[a].value>=obj.b1.value)&&(obj.t3[a].value<=obj.b2.value))
{
obj.t4[a].value='B+';
}
else if ((obj.t3[a].value>=obj.b3.value)&&(obj.t3[a].value<=obj.b4.value))
{
obj.t4[a].value='B';
}
else if ((obj.t3[a].value>=obj.c1.value)&&(obj.t3[a].value<=obj.c2.value))
{
obj.t4[a].value='C+';
}
else if ((obj.t3[a].value>=obj.c3.value)&&(obj.t3[a].value<=obj.c4.value))
{
obj.t4[a].value='C';
}
else if ((obj.t3[a].value>=obj.d1.value)&&(obj.t3[a].value<=obj.d2.value))
{
obj.t4[a].value='D+';
}
else if ((obj.t3[a].value>=obj.d3.value)&&(obj.t3[a].value<=obj.d4.value))
{
obj.t4[a].value='D';
}
else if (obj.t3[a].value<=obj.e2.value)
{
obj.t4[a].value='E';
}
}
}
</script>
</font><font face="AngsanaUPC, BrowalliaUPC, CordiaUPC"><strong></strong></font>
<table border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" >
<tr bordercolor="#000000" bgcolor="#FFFFFF">
<td width="150" height="15" align="center" ><strong>ช่วงคะแนน</strong></td>
<td width="55" height="15" align="center" ><strong>ระดับ</strong></td>
</tr>
<tr bordercolor="#000000" bgcolor="#FFFFFF">
<td width="150" height="15"><div align="center">
<input name="a1" type="text" id="a1" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" value="80" size="1" maxlength="3" style="width:24px;border:none;text-align:center; "/>
- 100</div></td>
<td width="55" height="15" align="center" >A</td>
</tr>
<tr bordercolor="#000000" bgcolor="#FFFFFF">
<td width="150" height="15"><div align="center">
<input name="b1" type="text" id="b1" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" value="75" size="1" maxlength="2" style="width:24px;border:none; text-align:center; "/>
-
<input name="b2" type="text" id="b2" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" value="79" size="1" maxlength="2" style="width:24px;border:none; text-align:center; "/>
</div></td>
<td width="55" height="15" align="center" > B+</td>
</tr>
<tr bordercolor="#000000" bgcolor="#FFFFFF">
<td width="150" height="15"><div align="center">
<input name="b3" type="text" id="b3" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" value="70" size="1" maxlength="2" style="width:24px;border:none; text-align:center; "/>
-
<input name="b4" type="text" id="b4" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" value="74" size="1" maxlength="2" style="width:24px;border:none; text-align:center; "/>
</div></td>
<td width="55" height="15" align="center" >B</td>
</tr>
<tr bordercolor="#000000" bgcolor="#FFFFFF">
<td width="150" height="26"><div align="center">
<input name="c1" type="text" id="c1" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" value="65" size="1" maxlength="2" style="width:24px;border:none; text-align:center; "/>
-
<input name="c2" type="text" id="c2" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" value="69" size="1" maxlength="2" style="width:24px;border:none; text-align:center; "/>
</div></td>
<td width="55" height="26" align="center" > C+</td>
</tr>
<tr bordercolor="#000000" bgcolor="#FFFFFF">
<td width="150" height="15"><div align="center">
<input name="c3" type="text" id="c3" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" value="60" size="1" maxlength="2" style="width:24px;border:none; text-align:center; "/>
-
<input name="c4" type="text" id="c4" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" value="64" size="1" maxlength="2" style="width:24px;border:none; text-align:center; "/>
</div></td>
<td width="55" height="15" align="center" >C</td>
</tr>
<tr bordercolor="#000000" bgcolor="#FFFFFF">
<td width="150" height="15"><div align="center">
<input name="d1" type="text" id="d1" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" value="55" size="1" maxlength="2" style="width:24px;border:none; text-align:center; "/>
-
<input name="d2" type="text" id="d2" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" value="59" size="1" maxlength="2" style="width:24px;border:none; text-align:center; "/>
</div></td>
<td width="55" height="15" align="center" > D+</td>
</tr>
<tr bordercolor="#000000" bgcolor="#FFFFFF">
<td width="150" height="15"><div align="center">
<input name="d3" type="text" id="d3" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" value="50" size="1" maxlength="2" style="width:24px;border:none; text-align:center;"/>
-
<input name="d4" type="text" id="d4" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" value="54" size="1" maxlength="2" style="width:24px;border:none; text-align:center; "/>
</div></td>
<td width="55" height="15" align="center" >D</td>
</tr>
<tr bordercolor="#000000" bgcolor="#FFFFFF">
<td width="150" height="15"><div align="center">
0 -
<input name="e2" type="text" id="e2" onFocus="sum()" onBlur="sum()" onChange="sum()" onKeyUp="sum()" value="49" size="1" maxlength="2" style="width:24px;border:none; text-align:center;"/>
</div></td>
<td width="55" height="15" align="center" > F</td>
</tr>
</table>
<div align="center"><font size="2"> </font></div>
ก็อบลงไว้ใน โคด้ได้เลยครับ ที่เหลือแค่ปรับแก้ค่าตรงคะแนนที่ ข้างล่างพอครับ ว่าจะเอาช่วงคะแนนเท่าไร ถึง เท่าไรครับ
|
|
|
|
|
Date :
2009-03-22 14:58:07 |
By :
mitsongkore |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณ sodseed และคุณ tongมากนะครับ ที่ให้แนวทาง ทำได้แล้วครับ
|
|
|
|
|
Date :
2009-03-22 19:30:37 |
By :
amornthep |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|