PHP判斷學(xué)習(xí)成績(jī),多重if判斷嵌套繼續(xù)懵逼,求助人為樂(lè)的牛
<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html?xmlns="http://www.w3.org/1999/xhtml"> <head> ????<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/> ????<title>無(wú)標(biāo)題文檔</title> ????<style?type="text/css"> ????????body{ ????????????font-size:18px; ????????} ????</style> </head> <body> ????????<?php ????????????$str=''; ????????if(isset($_GET['1name']))?{ ????????????$name?=?$_GET['1name']; ????????} ????????if?(empty($name))?{ ????????????$str?=?"姓名不能為空!"; ????????????return?false; ????????????} ????????if?(is_numeric($name))?{ ????????????$str?=?"姓名不能為數(shù)字"; ????????????return?false; ????????} ????????if?(isset($_GET['1score']))?{ ????????????$score?=?$_GET['1score']; ????????} ????????if?(empty($score))?{ ????????????$str?=?"成績(jī)不能為空"; ????????????return?false; ????????} ????????if?(is_numeric($score))?{ ????????????if?($score?<?0?||?$score?>?100)?{ ????????????????$str?=?"成績(jī)虛假,son?of?a?bitch"; ????????????}?else?{ ????????????????switch?((integer)($score?/?10))//0,1,2,3,...,10 ????????????????{ ????????????????????case?10: ????????????????????????$str?=?'A+'; ????????????????????????break; ????????????????????case?9: ????????????????????????$str?=?'A'; ????????????????????????break; ????????????????????case?8: ????????????????????????$str?=?'B'; ????????????????????????break; ????????????????????case?7: ????????????????????????$str?=?'C'; ????????????????????????break; ????????????????????case?6: ????????????????????????$str?=?'D'; ????????????????????????break; ????????????????????default: ????????????????????????$str?=?'fail'; ????????????????????????break; ????????????????} ????????????} ????????} ?????????> <form?action="#"?method="get"> ????請(qǐng)輸入學(xué)生的姓名: ????<input?type="text"??name="1name"?value="<?php?if(!empty($_POST["lname"])){?echo?$_GET["lname"]?;}??>"?/><br?/> ????請(qǐng)輸入學(xué)生的成績(jī): ????<input?type="text"??name="1score"?value="<?php?if(!empty($_POST["lscore"])){echo?$_GET["lscore"];}??>"?/><br?/> ????<input?type="submit"?value="提交"?/> </form> ????????<?php ????????echo?$str; ?????????> </body> </html>
輸出空白頁(yè)面;
<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html?xmlns="http://www.w3.org/1999/xhtml"> <head> ????<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/> ????<title>無(wú)標(biāo)題文檔</title> ????<style?type="text/css"> ????????body{ ????????????font-size:18px; ????????} ????</style> </head> <body> ????????<?php ????????????$str=''; ????????if(isset($_GET['1name']))?{ ????????????$name?=?$_GET['1name']; ????????????if?(empty($name))?{ ?????????????????$str?=?"姓名不能為空!";}else{ ????????????????if?(is_numeric($name))?{ ?????????????????????$str?=?"姓名不能為數(shù)字";}else{ ????????????????????if?(isset($_GET['lscore']))?{ ????????????????????????$score?=?$_GET['lscore'];} ????????????????????????if?(empty($score))?{ ?????????????????????????????$str?=?"成績(jī)不能為空";}else{ ????????????????????????????if?(is_numeric($score))?{ ????????????????????????????????if?($score?<?0?||?$score?>?100)?{ ?????????????????????????????????????$str?=?"成績(jī)虛假,son?of?a?bitch"; ????????????????????????????????}?else?{ ????????????????????????????????????switch?((integer)($score?/?10))//0,1,2,3,...,10 ????????????????????????????????????{ ????????????????????????????????????????case?10: ????????????????????????????????????????????$str?=?'A+'; ????????????????????????????????????????????break; ????????????????????????????????????????case?9: ????????????????????????????????????????????$str?=?'A'; ????????????????????????????????????????????break; ????????????????????????????????????????case?8: ????????????????????????????????????????????$str?=?'B'; ????????????????????????????????????????????break; ????????????????????????????????????????case?7: ????????????????????????????????????????????$str?=?'C'; ????????????????????????????????????????????break; ????????????????????????????????????????case?6: ????????????????????????????????????????????$str?=?'D'; ????????????????????????????????????????????break; ????????????????????????????????????????default: ????????????????????????????????????????????$str?=?'fail'; ????????????????????????????????????????????break; ????????????????????????????????????} ????????????????????????????????} ????????????????????????????} ????????????????????????} ????????????????????} ????????????????} ????????????} ?????????> <form?action="#"?method="get"> ????請(qǐng)輸入學(xué)生的姓名: ????<input?type="text"??name="1name"?value="<?php?if(!empty($_POST["lname"])){?echo?$_GET["lname"]?;}??>"?/><br?/> ????請(qǐng)輸入學(xué)生的成績(jī): ????<input?type="text"??name="1score"?value="<?php?if(!empty($_POST["lscore"])){echo?$_GET["lscore"];}??>"?/><br?/> ????<input?type="submit"?value="提交"?/> </form> ????????<?php ????????echo?$str; ?????????> </body> </html>
無(wú)法判斷成績(jī);
http://idcbgp.cn/wenda/detail/333114
原問(wèn)題
2016-10-28
2016-10-28
這種簡(jiǎn)單的問(wèn)題,就學(xué)著自己排查,不是所有人都有時(shí)間幫你排查的,很多人只是看一眼,猜測(cè)一下問(wèn)題所在,反而給你帶錯(cuò)方向。