Heim >php教程 >php手册 >基于Sql Server 2008的分布式数据库的实践(五)

基于Sql Server 2008的分布式数据库的实践(五)

WBOY
WBOYOriginal
2016-06-13 10:17:41953Durchsuche

程序设计

-----------------------------------------------------------------------------------------------------------------

Index.php————选择界面,并且实现学生和老师的注册

sql_ini.php————SQL配置文件

./student————学生的后台

./admin————老师的后台

-----------------------------------------------------------------------------------------------------------------

./student

cookie.php————cookie转跳文件

index1.php————后台界面

login.php————登录界面

loginout.php————cookie注销处理

main.php————主界面

menu.php————后台菜单

sclass.php————显示学生选课信息

score.php-————显示学生成绩

sinfo.php————显示*

sql_ini.php————SQL配置文件

up.php————后台表单处理文件

-----------------------------------------------------------------------------------------------------------------

./admin

class.php————显示老师课程信息

cookie.php————cookie转跳文件

index1.php————后台界面

info.php————显示老师资料(有权限设置)

login.php————登录界面

loginout.php————cookie注销处理

main.php————主界面

menu.php————后台菜单

score.php-————登记学生成绩

sql_ini.php————SQL配置文件

up.php————后台表单处理文件

程序解释

学生注册

<span  1</span> <span if</span>(<span isset</span>(<span $_POST</span>['addstudent'<span ]))
</span><span  2</span> <span {
</span><span  3</span>     <span //</span><span 判断是否有空,即没有输入的</span>
<span  4</span>     <span if</span>((<span $_POST</span>['sname']=='')||(<span $_POST</span>['sex']=='')||(<span $_POST</span>['school']=='')||(<span $_POST</span>['scount']=='')||(<span $_POST</span>['spwd1']=='')||(<span $_POST</span>['spwd2']==''<span ))
</span><span  5</span> <span     {
</span><span  6</span>         <span echo</span> '请输全信息!'<span ;
</span><span  7</span>         <span exit</span><span ();
</span><span  8</span> <span     }
</span><span  9</span>     <span //</span><span 把传递的数据赋值到变量里面</span>
<span 10</span>     <span $sname</span>=<span $_POST</span>['sname'<span ];
</span><span 11</span>     <span $sex</span>=<span $_POST</span>['sex'<span ];
</span><span 12</span>     <span $school</span>=<span $_POST</span>['school'<span ];
</span><span 13</span>     <span $scount</span>=<span $_POST</span>['scount'<span ];
</span><span 14</span>     <span $spwd1</span>=<span $_POST</span>['spwd1'<span ];
</span><span 15</span>     <span $spwd2</span>=<span $_POST</span>['spwd2'<span ];
</span><span 16</span>     <span $sid</span>=<span rand</span>(1,9999);<span //</span><span 随机一个学号
</span><span 17</span> <span     //判断两次密码是不是相同</span>
<span 18</span>     <span if</span>(<span $spwd1</span>==<span $spwd2</span><span )
</span><span 19</span> <span     {
</span><span 20</span>         <span //</span><span SQL Server 对数据处理前的操作</span>
<span 21</span> <span         sql();
</span><span 22</span>         <span //</span><span SQL语句</span>
<span 23</span>         <span $sql</span>="select * from [V3].[dbo].[V3_student]"<span ;
</span><span 24</span>         <span $result</span> = mssql_query(<span $sql</span><span );
</span><span 25</span>         <span //</span><span 从结果集中取得一行作为关联数组</span>
<span 26</span>         <span while</span> (<span $row</span> = mssql_fetch_array(<span $result</span>,<span  MSSQL_ASSOC))
</span><span 27</span> <span         {
</span><span 28</span>             <span //</span><span 二次判断是否登录帐号重复</span>
<span 29</span>             <span if</span>(<span $row</span>['scount']==<span $scount</span><span )
</span><span 30</span> <span             {
</span><span 31</span>                 <span //</span><span 报错并终止</span>
<span 32</span>                 <span echo</span> ("已经有人申请了这个帐号!"<span );
</span><span 33</span>                 <span exit</span><span ();        
</span><span 34</span> <span             }
</span><span 35</span> <span         }
</span><span 36</span>         <span //</span><span SQL语句插入到视图里面</span>
<span 37</span>         <span $sql_add</span>="<span INSERT INTO [V3].[dbo].[V3_student] ([sid],[sex],[sname],[school],[scount],[spwd]) 
</span><span 38</span>                         VALUES (".<span $sid</span>.",'".<span $sex</span>."','".<span $sname</span>."','".<span $school</span>."','".<span $scount</span>."','".<span $spwd1</span>."')"<span ;
</span><span 39</span>         <span $result_add</span> = mssql_query(<span $sql_add</span><span );
</span><span 40</span>         <span //</span><span 对SQL操作的结果的判断</span>
<span 41</span>         <span if</span>(<span $result_add</span><span )
</span><span 42</span>             {<span echo</span> "<center>注册成功!</center>"<span ;}
</span><span 43</span>         <span else</span> 
<span 44</span>             {<span echo</span> "sql出错!"<span ;}
</span><span 45</span> <span     }
</span><span 46</span>     <span else</span>
<span 47</span> <span     {
</span><span 48</span>         <span //</span><span 密码不相同报错并终止</span>
<span 49</span>         <span echo</span> ("两次密码不对"<span );
</span><span 50</span>         <span exit</span><span ();
</span><span 51</span> <span     }
</span><span 52</span> }

 

老师注册

<span  1</span> <span if</span>(<span isset</span>(<span $_POST</span>['addadmin'<span ]))
</span><span  2</span> <span {
</span><span  3</span>     <span //</span><span 判断是否有空,即没有输入的</span>
<span  4</span>     <span if</span>((<span $_POST</span>['name']=='')||(<span $_POST</span>['sex']=='')||(<span $_POST</span>['age']=='')||(<span $_POST</span>['count']=='')||(<span $_POST</span>['pwd']=='')||(<span $_POST</span>['pwd2']=='')||(<span $_POST</span>['ageage']=='')||(<span $_POST</span>['tel']=='')||(<span $_POST</span>['address']==''<span ))
</span><span  5</span> <span     {
</span><span  6</span>         <span echo</span> '请输全信息!'<span ;
</span><span  7</span>         <span exit</span><span ();
</span><span  8</span> <span     }    
</span><span  9</span>     <span //</span><span 把传递的数据赋值到变量里面</span>
<span 10</span>     <span $tname</span>=<span $_POST</span>['name'<span ];
</span><span 11</span>     <span $tsex</span>=<span $_POST</span>['sex'<span ];
</span><span 12</span>     <span $tage</span>=<span $_POST</span>['age'<span ];
</span><span 13</span>     <span $tcount</span>=<span $_POST</span>['count'<span ];
</span><span 14</span>     <span $tpwd</span>=<span $_POST</span>['pwd'<span ];
</span><span 15</span>     <span $tpwd2</span>=<span $_POST</span>['pwd2'<span ];
</span><span 16</span>     <span $age</span>=<span $_POST</span>['ageage'<span ];
</span><span 17</span>     <span $tel</span>=<span $_POST</span>['tel'<span ];
</span><span 18</span>     <span $address</span>=<span $_POST</span>['address'<span ];    
</span><span 19</span>     <span $tsuper</span>=1<span ;
</span><span 20</span>     <span $tidid</span>=<span rand</span>(1,9999<span );
</span><span 21</span>     <span //</span><span 判断两次密码是否相同</span>
<span 22</span>     <span if</span>(<span $tpwd</span>==<span $tpwd2</span><span )
</span><span 23</span> <span     {
</span><span 24</span>         <span //</span><span SQL Server 对数据处理前的操作</span>
<span 25</span> <span         sql();
</span><span 26</span>         <span //</span><span SQL语句</span>
<span 27</span>         <span $sql</span>="select * from [V3].[dbo].[teacher]"<span ;
</span><span 28</span>         <span $result</span> = mssql_query(<span $sql</span><span );
</span><span 29</span>         <span //</span><span 从结果集中取得一行作为关联数组</span>
<span 30</span>         <span while</span> (<span $row</span> = mssql_fetch_array(<span $result</span>,<span  MSSQL_ASSOC)) 
</span><span 31</span> <span         {
</span><span 32</span>             <span //</span><span 二次判断是否登录帐号重复</span>
<span 33</span>             <span if</span>(<span $row</span>['tcount']==<span $tcount</span><span )
</span><span 34</span> <span             {
</span><span 35</span>                 <span //</span><span 报错并终止</span>
<span 36</span>                 <span echo</span> ("已经有人申请了这个帐号!"<span );
</span><span 37</span>                 <span exit</span><span ();                
</span><span 38</span> <span             }
</span><span 39</span> <span         }
</span><span 40</span>         <span $sql_add</span>="EXEC [V3].[dbo].[V3_teacher] ".<span $tidid</span>.",'".<span $tname</span>."', '".<span $tage</span>."', '".<span $tsex</span>."', '".<span $tcount</span>."', '".<span $tpwd</span>."', '".<span $tsuper</span>."','".<span $age</span>."','".<span $tel</span>."','".<span $address</span>."'"<span ;
</span><span 41</span>         <span $result_add</span> = mssql_query(<span $sql_add</span><span );
</span><span 42</span>         <span if</span>(<span $result_add</span><span )
</span><span 43</span>             {<span echo</span> "<center>注册成功!</center>"<span ;}
</span><span 44</span>         <span else</span> 
<span 45</span>             {<span echo</span> "sql出错!"<span ;}    
</span><span 46</span> <span     }
</span><span 47</span>     <span else</span>
<span 48</span> <span     {
</span><span 49</span>         <span //</span><span 报错并终止</span>
<span 50</span>         <span echo</span> ("两次密码不对"<span );
</span><span 51</span>         <span exit</span><span ();
</span><span 52</span> <span     }
</span><span 53</span> }

学生登录和查看资料

<span  1</span> <span //</span><span cookie传递id</span>
<span  2</span>     <span $sid</span>=<span $_COOKIE</span>['uid'<span ];
</span><span  3</span> <span     sql();
</span><span  4</span>     <span //</span><span SQL 语句</span>
<span  5</span>     <span $query</span> = "SELECT * FROM [V3].[dbo].[V3_student] where [sid]=".<span $sid</span>.""<span ;
</span><span  6</span>     <span $result</span> = mssql_query(<span $query</span><span );
</span><span  7</span>     <span //</span><span 取得这个表有多少列</span>
<span  8</span>     <span $db_t_num</span>=mssql_num_fields(<span $result</span><span );
</span><span  9</span>     <span //</span><span 保存字段中文含义</span>
<span 10</span>     <span $arrname</span>[0]='学号'<span ;
</span><span 11</span>     <span $arrname</span>[1]='姓名'<span ;
</span><span 12</span>     <span $arrname</span>[2]='学院'<span ;
</span><span 13</span>     <span $arrname</span>[3]='帐号'<span ;
</span><span 14</span>     <span $arrname</span>[4]='密码'<span ;
</span><span 15</span>     <span /*</span><span ******************
</span><span 16</span> <span             HTML表格输出
</span><span 17</span> <span     ******************</span><span */</span>
<span 18</span>     <span echo</span> "<table border='1' >\n"<span ;
</span><span 19</span>     <span echo</span> "\t<tr>\n"<span ;
</span><span 20</span>     <span for</span>(<span $num</span>=0;<span $num</span><<span $db_t_num</span>;<span $num</span>++<span )
</span><span 21</span> <span     {
</span><span 22</span>         <span //</span><span 输出字段中文含义</span>
<span 23</span>         <span echo</span> "\t\t<td>".<span $arrname</span>[<span $num</span>]."</td>\n"<span ;
</span><span 24</span> <span     }
</span><span 25</span>     <span echo</span> "\t</tr>\n"<span ;
</span><span 26</span>     <span while</span> (<span $row</span> = mssql_fetch_array(<span $result</span>,<span  MSSQL_ASSOC)) 
</span><span 27</span> <span     { 
</span><span 28</span>         <span //</span><span 输出内容</span>
<span 29</span>       <span echo</span> "\t<tr>\n"<span ;
</span><span 30</span>             <span echo</span> '<td>'.<span $row</span>["sid"].'</td>'<span ;
</span><span 31</span>             <span echo</span> '<td>'.<span $row</span>["sname"].'</td>'<span ;
</span><span 32</span>             <span echo</span> '<td>'.<span $row</span>["school"].'</td>'<span ;
</span><span 33</span>             <span echo</span> '<td>'.<span $row</span>["scount"].'</td>'<span ;
</span><span 34</span>             <span echo</span> '<td>******</td>';<span //</span><span 隐藏的写法</span>
<span 35</span>         <span echo</span> "\t</tr>\n"<span ;
</span><span 36</span> <span     }
</span><span 37</span>     <span echo</span> "</table>\n"<span ;    
</span><span 38</span>     <span //</span><span 释放SQL链接</span>
<span 39</span>     mssql_free_result(<span $result</span>);

学生选课

<span  1</span> <span //</span><span GET得到是选课操作</span>
<span  2</span> <span if</span>(<span $_GET</span>['action']=='do'<span )
</span><span  3</span> <span {
</span><span  4</span>     <span //</span><span cookie传递sid</span>
<span  5</span>     <span $id</span>=<span $_COOKIE</span>["uid"<span ];
</span><span  6</span> <span     sql();
</span><span  7</span>     <span //</span><span sid选了什么课,使check打上勾</span>
<span  8</span>     <span $sql_do</span>="SELECT * FROM [V3].[dbo].[class] where [sid]=".<span $id</span>.""<span ;
</span><span  9</span>     <span $result_do</span> = mssql_query(<span $sql_do</span><span );
</span><span 10</span>     <span $ii</span>=0;<span //</span><span 保存学生所选的课</span>
<span 11</span>     <span while</span> (<span $row</span> = mssql_fetch_array(<span $result_do</span>,<span  MSSQL_ASSOC)) 
</span><span 12</span> <span     {
</span><span 13</span>         <span $s_cid_do</span>[<span $ii</span>]=<span $row</span>['cid'<span ];
</span><span 14</span>         <span $ii</span>++<span ;
</span><span 15</span> <span     }     
</span><span 16</span>     
<span 17</span>     <span //</span><span SQL语句通过默认学生sid=0取得课名cname和课号cid和老师tid</span>
<span 18</span>     <span $sql_class</span>="SELECT * FROM [V3].[dbo].[class] where [sid] = 0"<span ;
</span><span 19</span>     <span $result_class</span> = mssql_query(<span $sql_class</span><span );    
</span><span 20</span>     <span $i</span>=0;<span //</span><span 保存有多少行</span>
<span 21</span>     <span while</span> (<span $row</span> = mssql_fetch_array(<span $result_class</span>,<span  MSSQL_ASSOC)) 
</span><span 22</span> <span     {
</span><span 23</span>         <span $class_tid</span>[<span $i</span>]=<span $row</span>['tid'<span ];
</span><span 24</span>         <span $class_cid</span>[<span $i</span>]=<span $row</span>['cid'<span ];
</span><span 25</span>         <span $class_name</span>[<span $i</span>]=<span $row</span>['cname'<span ];
</span><span 26</span>         <span $i</span>++<span ;
</span><span 27</span> <span     }
</span><span 28</span>     <span //</span><span SQL语句通过tid取得老师名字,教学年龄和性别</span>
<span 29</span>     <span for</span>(<span $a</span>=0;<span $a</span><<span $i</span>;<span $a</span>++<span )
</span><span 30</span> <span     {
</span><span 31</span>         <span $sql_t</span>[<span $a</span>]="SELECT * FROM [V3].[dbo].[teacher] where [tid]=".<span $class_tid</span>[<span $a</span>].""<span ;
</span><span 32</span>         <span $result_t</span>[<span $a</span>]= mssql_query(<span $sql_t</span>[<span $a</span><span ]);
</span><span 33</span>         <span while</span> (<span $class_t</span> = mssql_fetch_array(<span $result_t</span>[<span $a</span>],<span  MSSQL_ASSOC)) 
</span><span 34</span> <span         {
</span><span 35</span>             <span $class_tsex</span>[<span $a</span>]=<span $class_t</span>['tsex'<span ];
</span><span 36</span>             <span $class_tage</span>[<span $a</span>]=<span $class_t</span>['tage'<span ];
</span><span 37</span>             <span $class_tname</span>[<span $a</span>]=<span $class_t</span>['tname'<span ];
</span><span 38</span> <span         }     
</span><span 39</span> <span     }
</span><span 40</span>     <span //</span><span 保存字段中文含义</span>
<span 41</span>     <span $arrname</span>[0]='课号'<span ;
</span><span 42</span>     <span $arrname</span>[1]='课名'<span ;
</span><span 43</span>     <span $arrname</span>[2]='老师名字'<span ;
</span><span 44</span>     <span $arrname</span>[3]='老师编号'<span ;
</span><span 45</span>     <span $arrname</span>[4]='老师教学年龄'<span ;
</span><span 46</span>     <span $arrname</span>[5]='老师性别'<span ;
</span><span 47</span>     <span $arrname</span>[6]='选课'<span ;
</span><span 48</span>     <span /*</span><span ******************
</span><span 49</span> <span             HTML表格输出
</span><span 50</span> <span     ******************</span><span */</span>
<span 51</span>     <span echo</span> '<form action="up.php" method="POST">'<span ;
</span><span 52</span>     <span echo</span> "<table border='1' >\n"<span ;
</span><span 53</span>     <span echo</span> "\t<tr><td colspan='7' align='center'>选课系统</td></tr>\n"<span ;
</span><span 54</span>     <span echo</span> "\t<tr>\n"<span ;
</span><span 55</span>     <span echo</span> "\t<tr>\n"<span ;
</span><span 56</span>     <span //</span><span 有6列</span>
<span 57</span>     <span for</span>(<span $num</span>=0;<span $num</span><7;<span $num</span>++<span )
</span><span 58</span> <span     {
</span><span 59</span>         <span echo</span> "\t\t<td>".<span $arrname</span>[<span $num</span>]."</td>\n"<span ;
</span><span 60</span> <span     }
</span><span 61</span>     <span for</span>(<span $a</span>=0;<span $a</span><<span $i</span>;<span $a</span>++<span )
</span><span 62</span> <span     {
</span><span 63</span>         <span //</span><span check初始化</span>
<span 64</span>         <span $check</span> = ''<span ;
</span><span 65</span>         <span //</span><span 判断是男是女</span>
<span 66</span>         <span if</span>(<span $class_tsex</span>[<span $a</span>]=='0'<span )
</span><span 67</span>                 <span $class_tsex</span>[<span $a</span>]='男'<span ;
</span><span 68</span>         <span else</span>
<span 69</span>                 <span $class_tsex</span>[<span $a</span>]='女'<span ;
</span><span 70</span>         <span //</span><span 判断选了这门课</span>
<span 71</span>         <span for</span>(<span $b</span>=0;<span $b</span><<span $ii</span>;<span $b</span>++<span )
</span><span 72</span> <span         {
</span><span 73</span>             <span if</span>(<span $class_cid</span>[<span $a</span>]==<span $s_cid_do</span>[<span $b</span><span ])
</span><span 74</span> <span             {
</span><span 75</span>                 <span $check</span> = 'checked'<span ;
</span><span 76</span> <span             }
</span><span 77</span> <span         }
</span><span 78</span>         <span echo</span> "\t<tr>\n"<span ;
</span><span 79</span>             <span echo</span> '<td>'.<span $class_cid</span>[<span $a</span>].'</td>'<span ;
</span><span 80</span>             <span echo</span> '<td>'.<span $class_name</span>[<span $a</span>].'</td>'<span ;
</span><span 81</span>             <span echo</span> '<td>'.<span $class_tname</span>[<span $a</span>].'</td>'<span ;
</span><span 82</span>             <span echo</span> '<td>'.<span $class_tid</span>[<span $a</span>].'</td>'<span ;
</span><span 83</span>             <span echo</span> '<td>'.<span $class_tage</span>[<span $a</span>].'</td>'<span ;
</span><span 84</span>             <span echo</span> '<td>'.<span $class_tsex</span>[<span $a</span>].'</td>'<span ;
</span><span 85</span>             <span echo</span> '<td><input type="checkbox" name=pa_'.<span $class_cid</span>[<span $a</span>].' '.<span $check</span>.'></td>';<span //</span><span name=pa_'.$class_cid[$a]这样写是为了出现BUG</span>
<span 86</span>         <span echo</span> "\t</tr>\n"<span ;
</span><span 87</span> <span     }
</span><span 88</span>     <span echo</span> "\t<tr><td colspan='7' align='center'><input type='submit' name='sub' value='确认课程'></td></tr>\n"<span ;
</span><span 89</span>     <span echo</span> "</table>\n"<span ;
</span><span 90</span>     <span echo</span> "</form>"<span ;
</span><span 91</span> }

 

学生退课

<span  1</span> <span //</span><span GET传递操作,为退课操作</span>
<span  2</span> <span if</span>(<span $_GET</span>['action']=='mine'<span )
</span><span  3</span> <span {
</span><span  4</span>     <span //</span><span cookie传递sid</span>
<span  5</span>     <span $id</span>=<span $_COOKIE</span>["uid"<span ];
</span><span  6</span> <span     sql();
</span><span  7</span>     <span //</span><span SQL语句通过学号sid取得课号cid和tid和课名</span>
<span  8</span>     <span $sql_s</span>="SELECT * FROM [V3].[dbo].[class] where [sid]=".<span $id</span>.""<span ;
</span><span  9</span>     <span $result_s</span> = mssql_query(<span $sql_s</span><span );
</span><span 10</span>     <span $i</span>=0;<span //</span><span 保存有多少行</span>
<span 11</span>     <span while</span> (<span $row</span> = mssql_fetch_array(<span $result_s</span>,<span  MSSQL_ASSOC)) 
</span><span 12</span> <span     {
</span><span 13</span>         <span $s_cid</span>[<span $i</span>]=<span $row</span>['cid'<span ];
</span><span 14</span>         <span $s_cname</span>[<span $i</span>]=<span $row</span>['cname'<span ];
</span><span 15</span>         <span $s_tid</span>[<span $i</span>]=<span $row</span>['tid'<span ];
</span><span 16</span>         <span $i</span>++<span ;
</span><span 17</span> <span     }     
</span><span 18</span>     <span //</span><span SQL语句通过tid得到上课的老师名字以及教学年龄和性别</span>
<span 19</span>     <span for</span>(<span $a</span>=0;<span $a</span><<span $i</span>;<span $a</span>++<span )
</span><span 20</span> <span     {
</span><span 21</span>         <span $sql_s_t</span>[<span $a</span>]="SELECT * from [V3].[dbo].[teacher] where [tid]=".<span $s_tid</span>[<span $a</span>].""<span ;
</span><span 22</span>         <span $result_s_t</span>[<span $a</span>] = mssql_query(<span $sql_s_t</span>[<span $a</span><span ]);
</span><span 23</span>         <span while</span> (<span $s_t</span> = mssql_fetch_array(<span $result_s_t</span>[<span $a</span>],<span  MSSQL_ASSOC)) 
</span><span 24</span> <span         {
</span><span 25</span>             <span $s_tsex</span>[<span $a</span>]=<span $s_t</span>['tsex'<span ];
</span><span 26</span>             <span $s_tage</span>[<span $a</span>]=<span $s_t</span>['tage'<span ];
</span><span 27</span>             <span $s_tname</span>[<span $a</span>]=<span $s_t</span>['tname'<span ];
</span><span 28</span> <span         }     
</span><span 29</span> <span     }
</span><span 30</span>     <span //</span><span 保存字段中文含义</span>
<span 31</span>     <span $arrname</span>[0]='课号'<span ;
</span><span 32</span>     <span $arrname</span>[1]='课名'<span ;
</span><span 33</span>     <span $arrname</span>[2]='老师名字'<span ;
</span><span 34</span>     <span $arrname</span>[3]='老师编号'<span ;
</span><span 35</span>     <span $arrname</span>[4]='老师教学年龄'<span ;
</span><span 36</span>     <span $arrname</span>[5]='老师性别'<span ;
</span><span 37</span>     <span $arrname</span>[6]='退课'<span ;
</span><span 38</span>     <span /*</span><span ******************
</span><span 39</span> <span             HTML表格输出
</span><span 40</span> <span     ******************</span><span */</span>
<span 41</span>     <span echo</span> '<form action="up.php" method="POST">'<span ;
</span><span 42</span>     <span echo</span> "<table border='1' >\n"<span ;
</span><span 43</span>     <span echo</span> "\t<tr><td colspan='7' align='center'>我选上的课</td></tr>\n"<span ;
</span><span 44</span>     <span echo</span> "\t<tr>\n"<span ;
</span><span 45</span>     <span echo</span> "\t<tr>\n"<span ;
</span><span 46</span>     <span //</span><span 有7列</span>
<span 47</span>     <span for</span>(<span $num</span>=0;<span $num</span><7;<span $num</span>++<span )
</span><span 48</span> <span     {
</span><span 49</span>         <span echo</span> "\t\t<td>".<span $arrname</span>[<span $num</span>]."</td>\n"<span ;
</span><span 50</span> <span     }
</span><span 51</span>     <span echo</span> "\t</tr>\n"<span ;
</span><span 52</span>     <span for</span>(<span $a</span>=0;<span $a</span><<span $i</span>;<span $a</span>++<span )
</span><span 53</span> <span     {
</span><span 54</span>         <span //</span><span 判断是男是女</span>
<span 55</span>         <span if</span>(<span $s_tsex</span>[<span $a</span>]=='0'<span )
</span><span 56</span>                 <span $s_tsex</span>[<span $a</span>]='男'<span ;
</span><span 57</span>         <span else</span>
<span 58</span>                 <span $s_tsex</span>[<span $a</span>]='女'<span ;
</span><span 59</span>         <span echo</span> "\t<tr>\n"<span ;
</span><span 60</span>             <span echo</span> '<td>'.<span $s_cid</span>[<span $a</span>].'</td>'<span ;
</span><span 61</span>             <span echo</span> '<td>'.<span $s_cname</span>[<span $a</span>].'</td>'<span ;
</span><span 62</span>             <span echo</span> '<td>'.<span $s_tname</span>[<span $a</span>].'</td>'<span ;
</span><span 63</span>             <span echo</span> '<td>'.<span $s_tid</span>[<span $a</span>].'</td>'<span ;
</span><span 64</span>             <span echo</span> '<td>'.<span $s_tage</span>[<span $a</span>].'</td>'<span ;
</span><span 65</span>             <span echo</span> '<td>'.<span $s_tsex</span>[<span $a</span>].'</td>'<span ;
</span><span 66</span>             <span echo</span> '<td><input type="checkbox" name="ma_'.<span $s_cid</span>[<span $a</span>].'" ></td></td>'<span ;
</span><span 67</span>         <span echo</span> "\t</tr>\n"<span ;
</span><span 68</span> <span     }
</span><span 69</span>     <span echo</span> "\t<tr><td colspan='7' align='center'><input type='submit' name='delsub' value='确认退课'></td></tr>\n"<span ;
</span><span 70</span>     <span echo</span> "</table>\n"<span ;
</span><span 71</span>     <span echo</span> "</form>"<span ;
</span><span 72</span> }

学生查看成绩

<span  1</span> <span //</span><span 通过cookie得到sid</span>
<span  2</span>     <span $id</span>=<span $_COOKIE</span>['uid'<span ];
</span><span  3</span> <span     sql();
</span><span  4</span>     <span //</span><span SQL语句通过学号sid取得课号cid和tid和课名</span>
<span  5</span>     <span $sql_s</span>="SELECT * FROM [V3].[dbo].[class] where [sid]=".<span $id</span>.""<span ;
</span><span  6</span>     <span $result_s</span> = mssql_query(<span $sql_s</span><span );
</span><span  7</span>     <span $i</span>=0;<span //</span><span 保存有多少行</span>
<span  8</span>     <span while</span> (<span $row</span> = mssql_fetch_array(<span $result_s</span>,<span  MSSQL_ASSOC)) 
</span><span  9</span> <span     {
</span><span 10</span>         <span $s_cid</span>[<span $i</span>]=<span $row</span>['cid'<span ];
</span><span 11</span>         <span $s_cname</span>[<span $i</span>]=<span $row</span>['cname'<span ];
</span><span 12</span>         <span $s_tid</span>[<span $i</span>]=<span $row</span>['tid'<span ];
</span><span 13</span>         <span $s_score</span>[<span $i</span>]=<span $row</span>['score'<span ];        
</span><span 14</span>         <span $i</span>++<span ;
</span><span 15</span> <span     }
</span><span 16</span>     <span //</span><span SQL语句通过tid得到上课的老师名字以及教学年龄和性别</span>
<span 17</span>     <span for</span>(<span $a</span>=0;<span $a</span><<span $i</span>;<span $a</span>++<span )
</span><span 18</span> <span     {
</span><span 19</span>         <span $sql_s_t</span>[<span $a</span>]="SELECT * from [V3].[dbo].[teacher] where [tid]=".<span $s_tid</span>[<span $a</span>].""<span ;
</span><span 20</span>         <span $result_s_t</span>[<span $a</span>] = mssql_query(<span $sql_s_t</span>[<span $a</span><span ]);
</span><span 21</span>         <span while</span> (<span $s_t</span> = mssql_fetch_array(<span $result_s_t</span>[<span $a</span>],<span  MSSQL_ASSOC)) 
</span><span 22</span> <span         {
</span><span 23</span>             <span $s_tsex</span>[<span $a</span>]=<span $s_t</span>['tsex'<span ];
</span><span 24</span>             <span $s_tage</span>[<span $a</span>]=<span $s_t</span>['tage'<span ];
</span><span 25</span>             <span $s_tname</span>[<span $a</span>]=<span $s_t</span>['tname'<span ];
</span><span 26</span> <span         }     
</span><span 27</span> <span     }
</span><span 28</span>     <span //</span><span 保存字段中文含义</span>
<span 29</span>     <span $arrname</span>[0]='课号'<span ;
</span><span 30</span>     <span $arrname</span>[1]='课名'<span ;
</span><span 31</span>     <span $arrname</span>[2]='老师名字'<span ;
</span><span 32</span>     <span $arrname</span>[3]='老师编号'<span ;
</span><span 33</span>     <span $arrname</span>[4]='老师教学年龄'<span ;
</span><span 34</span>     <span $arrname</span>[5]='老师性别'<span ;
</span><span 35</span>     <span $arrname</span>[6]='分数'<span ;     
</span><span 36</span>         <span /*</span><span ******************
</span><span 37</span> <span             HTML表格输出
</span><span 38</span> <span     ******************</span><span */</span>
<span 39</span>     <span echo</span> "<table border='1' >\n"<span ;
</span><span 40</span>     <span echo</span> "\t<tr><td colspan='7' align='center'>我选上的课</td></tr>\n"<span ;
</span><span 41</span>     <span echo</span> "\t<tr>\n"<span ;
</span><span 42</span>     <span echo</span> "\t<tr>\n"<span ;
</span><span 43</span>     <span //</span><span 有7列</span>
<span 44</span>     <span for</span>(<span $num</span>=0;<span $num</span><7;<span $num</span>++<span )
</span><span 45</span> <span     {
</span><span 46</span>         <span echo</span> "\t\t<td>".<span $arrname</span>[<span $num</span>]."</td>\n"<span ;
</span><span 47</span> <span     }
</span><span 48</span>     <span echo</span> "\t</tr>\n"<span ;
</span><span 49</span>     <span for</span>(<span $a</span>=0;<span $a</span><<span $i</span>;<span $a</span>++<span )
</span><span 50</span> <span     {
</span><span 51</span>         <span if</span>(<span $s_tsex</span>[<span $a</span>]=='0'<span )
</span><span 52</span>                 <span $s_tsex</span>[<span $a</span>]='男'<span ;
</span><span 53</span>         <span else</span>
<span 54</span>                 <span $s_tsex</span>[<span $a</span>]='女'<span ;
</span><span 55</span>         <span //</span><span 判断是否上成绩,若为999,则是没有上成绩</span>
<span 56</span>         <span if</span>(<span $s_score</span>[<span $a</span>]=='999'<span )
</span><span 57</span> <span         {
</span><span 58</span>             <span $s_score</span>[<span $a</span>]='未上成绩'<span ;
</span><span 59</span> <span         }
</span><span 60</span>         <span echo</span> "\t<tr>\n"<span ;
</span><span 61</span>             <span echo</span> '<td>'.<span $s_cid</span>[<span $a</span>].'</td>'<span ;
</span><span 62</span>             <span echo</span> '<td>'.<span $s_cname</span>[<span $a</span>].'</td>'<span ;
</span><span 63</span>             <span echo</span> '<td>'.<span $s_tname</span>[<span $a</span>].'</td>'<span ;
</span><span 64</span>             <span echo</span> '<td>'.<span $s_tid</span>[<span $a</span>].'</td>'<span ;
</span><span 65</span>             <span echo</span> '<td>'.<span $s_tage</span>[<span $a</span>].'</td>'<span ;
</span><span 66</span>             <span echo</span> '<td>'.<span $s_tsex</span>[<span $a</span>].'</td>'<span ;
</span><span 67</span>             <span echo</span> '<td>'.<span $s_score</span>[<span $a</span>].'</td>'<span ;
</span><span 68</span>             
<span 69</span>         <span echo</span> "\t</tr>\n"<span ;
</span><span 70</span> <span     }
</span><span 71</span>     <span echo</span> "</table>\n";

老师登录和查看所有资料(权限限制)

<span  1</span> <span //</span><span GET传递信息,显示所以老师(权限限制)</span>
<span  2</span> <span if</span>(<span $_GET</span>['people']=='all'<span )
</span><span  3</span> <span {
</span><span  4</span>     <span if</span>(<span $_COOKIE</span>["super"]=='10'<span )
</span><span  5</span> <span     {
</span><span  6</span> <span         sql();
</span><span  7</span>         <span //</span><span SQL 语句</span>
<span  8</span>         <span $query</span> = "SELECT * FROM [V3].[dbo].[teacher]"<span ;
</span><span  9</span>         <span $result</span> = mssql_query(<span $query</span><span );
</span><span 10</span>     
<span 11</span>         <span /*</span><span ******************
</span><span 12</span> <span                 HTML表格输出
</span><span 13</span> <span         ******************</span><span */</span>
<span 14</span>         <span echo</span> "<table border='1' >\n"<span ;
</span><span 15</span>         <span //</span><span 取得结果集中字段的数目</span>
<span 16</span>         <span $db_t_num</span>=mssql_num_fields(<span $result</span><span );
</span><span 17</span>         <span //</span><span 保存字段中文含义</span>
<span 18</span>         <span $arrname</span>[0]='编号'<span ;
</span><span 19</span>         <span $arrname</span>[1]='姓名'<span ;
</span><span 20</span>         <span $arrname</span>[2]='教学年龄'<span ;
</span><span 21</span>         <span $arrname</span>[3]='性别'<span ;
</span><span 22</span>         <span $arrname</span>[4]='登录帐号'<span ;
</span><span 23</span>         <span $arrname</span>[5]='登录密码'<span ;
</span><span 24</span>         <span $arrname</span>[6]='管理权限'<span ;
</span><span 25</span>         
<span 26</span>         <span echo</span> "\t<tr>\n"<span ;
</span><span 27</span>         <span for</span>(<span $num</span>=0;<span $num</span><<span $db_t_num</span>;<span $num</span>++<span )
</span><span 28</span> <span         {
</span><span 29</span>             <span echo</span> "\t\t<td>".<span $arrname</span>[<span $num</span>]."</td>\n"<span ;
</span><span 30</span> <span         }
</span><span 31</span>         <span echo</span> "\t</tr>\n"<span ;
</span><span 32</span>         <span //</span><span 从结果集中取得一行作为关联数组</span>
<span 33</span>         <span while</span> (<span $row</span> = mssql_fetch_array(<span $result</span>,<span  MSSQL_ASSOC)) 
</span><span 34</span> <span         { 
</span><span 35</span>             <span //</span><span 判断之后显示男女中文</span>
<span 36</span>             <span if</span>(<span $row</span>["tsex"]=='0'<span )
</span><span 37</span>                 <span $row</span>["tsex"]='男'<span ;
</span><span 38</span>             <span else</span>
<span 39</span>                 <span $row</span>["tsex"]='女'<span ;
</span><span 40</span>             <span //</span><span 判断是不是超级管理员</span>
<span 41</span>             <span if</span>(<span $row</span>["tsuper"]=='10'<span )
</span><span 42</span>                 <span $row</span>["tsuper"]='超级老师管理员'<span ;
</span><span 43</span>             <span else</span>
<span 44</span>                 <span $row</span>["tsuper"]='普通老师管理员'<span ;
</span><span 45</span>             
<span 46</span>                 <span //</span><span 输出内容</span>
<span 47</span>             <span echo</span> "\t<tr>\n"<span ;
</span><span 48</span>                     <span echo</span> '<td>'.<span $row</span>["tid"].'</td>'<span ;
</span><span 49</span>                     <span echo</span> '<td>'.<span $row</span>["tname"].'</td>'<span ;
</span><span 50</span>                     <span echo</span> '<td>'.<span $row</span>["tage"].'</td>'<span ;
</span><span 51</span>                     <span echo</span> '<td>'.<span $row</span>["tsex"].'</td>'<span ;
</span><span 52</span>                     <span echo</span> '<td>'.<span $row</span>["tcount"].'</td>'<span ;
</span><span 53</span>                     <span echo</span> '<td>******</td>';<span //</span><span 隐藏的写法</span>
<span 54</span>                     <span echo</span> '<td>'.<span $row</span>["tsuper"].'</td>'<span ;
</span><span 55</span>             <span echo</span> "\t</tr>\n"<span ;
</span><span 56</span> <span         }    
</span><span 57</span>         <span echo</span> "</table>\n"<span ;
</span><span 58</span>         
<span 59</span>         <span //</span><span 释放SQL链接</span>
<span 60</span>         mssql_free_result(<span $result</span><span );
</span><span 61</span> <span     }
</span><span 62</span>     <span else</span>
<span 63</span> <span     {
</span><span 64</span>         <span echo</span> "没有权限查看!"<span ;
</span><span 65</span> <span     }
</span><span 66</span> }

老师查看资料

<span  1</span> <span //</span><span GET传递信息,显示自己信息</span>
<span  2</span> <span if</span>(<span $_GET</span>['people']=='me'<span )
</span><span  3</span> <span {
</span><span  4</span>     <span //</span><span cookie传输tid</span>
<span  5</span>     <span $id</span>=<span $_COOKIE</span>["uid"<span ];
</span><span  6</span>     <span //</span><span SQL 语句</span>
<span  7</span>     <span $query</span> = "SELECT * FROM [V3].[dbo].[teacher] where tid=".<span $id</span>.""<span ;
</span><span  8</span>     <span $result</span> = mssql_query(<span $query</span><span );
</span><span  9</span>     <span /*</span><span ******************
</span><span 10</span> <span             HTML表格输出
</span><span 11</span> <span     ******************</span><span */</span>
<span 12</span>     <span echo</span> "<table border='1' >\n"<span ;
</span><span 13</span>     <span //</span><span 取得结果集中字段的数目</span>
<span 14</span>     <span $db_t_num</span>=mssql_num_fields(<span $result</span><span );
</span><span 15</span>     <span //</span><span 保存字段中文含义</span>
<span 16</span>     <span $arrname</span>[0]='编号'<span ;
</span><span 17</span>     <span $arrname</span>[1]='姓名'<span ;
</span><span 18</span>     <span $arrname</span>[2]='教学年龄'<span ;
</span><span 19</span>     <span $arrname</span>[3]='性别'<span ;
</span><span 20</span>     <span $arrname</span>[4]='登录帐号'<span ;
</span><span 21</span>     <span $arrname</span>[5]='登录密码'<span ;
</span><span 22</span>     <span $arrname</span>[6]='管理权限'<span ;
</span><span 23</span>     
<span 24</span>     <span echo</span> "\t<tr>\n"<span ;
</span><span 25</span>     <span for</span>(<span $num</span>=0;<span $num</span><<span $db_t_num</span>;<span $num</span>++<span )
</span><span 26</span> <span     {
</span><span 27</span>         <span echo</span> "\t\t<td>".<span $arrname</span>[<span $num</span>]."</td>\n"<span ;
</span><span 28</span> <span     }
</span><span 29</span>     <span echo</span> "\t</tr>\n"<span ;
</span><span 30</span>     <span while</span> (<span $row</span> = mssql_fetch_array(<span $result</span>,<span  MSSQL_ASSOC)) 
</span><span 31</span> <span     { 
</span><span 32</span>         <span //</span><span 判断之后显示男女中文</span>
<span 33</span>         <span if</span>(<span $row</span>["tsex"]=='0'<span )
</span><span 34</span>                 <span $row</span>["tsex"]='男'<span ;
</span><span 35</span>             <span else</span>
<span 36</span>                 <span $row</span>["tsex"]='女'<span ;
</span><span 37</span>             <span //</span><span 判断是不是超级管理员</span>
<span 38</span>             <span if</span>(<span $row</span>["tsuper"]=='10'<span )
</span><span 39</span>                 <span $row</span>["tsuper"]='超级老师管理员'<span ;
</span><span 40</span>             <span else</span>
<span 41</span>                 <span $row</span>["tsuper"]='普通老师管理员'<span ;
</span><span 42</span>             
<span 43</span>                 <span //</span><span 输出内容</span>
<span 44</span>             <span echo</span> "\t<tr>\n"<span ;
</span><span 45</span>                     <span echo</span> '<td>'.<span $row</span>["tid"].'</td>'<span ;
</span><span 46</span>                     <span echo</span> '<td>'.<span $row</span>["tname"].'</td>'<span ;
</span><span 47</span>                     <span echo</span> '<td>'.<span $row</span>["tage"].'</td>'<span ;
</span><span 48</span>                     <span echo</span> '<td>'.<span $row</span>["tsex"].'</td>'<span ;
</span><span 49</span>                     <span echo</span> '<td>'.<span $row</span>["tcount"].'</td>'<span ;
</span><span 50</span>                     <span echo</span> '<td>******</td>';<span //</span><span 隐藏的写法</span>
<span 51</span>                     <span echo</span> '<td>'.<span $row</span>["tsuper"].'</td>'<span ;
</span><span 52</span>             <span echo</span> "\t</tr>\n"<span ;
</span><span 53</span> <span     }
</span><span 54</span>     <span echo</span> "</table>\n"<span ;
</span><span 55</span>     
<span 56</span>     <span //</span><span 释放SQL链接</span>
<span 57</span>         mssql_free_result(<span $result</span><span );
</span><span 58</span> }

老师添加老师(权限限制)

<span  1</span> <span //</span><span POST传递信息</span>
<span  2</span> <span if</span>(<span isset</span>(<span $_POST</span>['addsub'<span ]))
</span><span  3</span> <span {
</span><span  4</span>     <span //</span><span 把传递的信息传到变量里面</span>
<span  5</span>     <span $tname</span>=<span $_POST</span>['name'<span ];
</span><span  6</span>     <span $tsex</span>=<span $_POST</span>['sex'<span ];
</span><span  7</span>     <span $tage</span>=<span $_POST</span>['age'<span ];
</span><span  8</span>     <span $tcount</span>=<span $_POST</span>['count'<span ];
</span><span  9</span>     <span $tpwd</span>=<span $_POST</span>['pwd'<span ];
</span><span 10</span>     <span $tpwd2</span>=<span $_POST</span>['pwd2'<span ];
</span><span 11</span>     <span $tsuper</span>=<span $_POST</span>['super'<span ];
</span><span 12</span>     <span $tidid</span>=<span $_POST</span>['idid'<span ];
</span><span 13</span>     <span $age</span>=<span $_POST</span>['ageage'<span ];
</span><span 14</span>     <span $tel</span>=<span $_POST</span>['tel'<span ];
</span><span 15</span>     <span $address</span>=<span $_POST</span>['address'<span ];        
</span><span 16</span>     <span //</span><span 判断两次密码是否相同</span>
<span 17</span>     <span if</span>(<span $tpwd</span>==<span $tpwd2</span><span )
</span><span 18</span> <span     {
</span><span 19</span> <span         sql();
</span><span 20</span>         <span //</span><span SQL语句</span>
<span 21</span>         <span $sql</span>="select * from [V3].[dbo].[teacher]"<span ;
</span><span 22</span>         <span $result</span> = mssql_query(<span $sql</span><span );
</span><span 23</span>         <span //</span><span 从结果集中取得一行作为关联数组</span>
<span 24</span>         <span while</span> (<span $row</span> = mssql_fetch_array(<span $result</span>,<span  MSSQL_ASSOC)) 
</span><span 25</span> <span         {
</span><span 26</span>             <span //</span><span 二次判断是否登录帐号重复</span>
<span 27</span>             <span if</span>(<span $row</span>['tcount']==<span $tcount</span><span )
</span><span 28</span> <span             {
</span><span 29</span>                 <span //</span><span 报错并终止</span>
<span 30</span>                 <span echo</span> ("已经有人申请了这个帐号!"<span );
</span><span 31</span>                 <span exit</span><span ();                
</span><span 32</span> <span             }
</span><span 33</span> <span         }
</span><span 34</span>         <span //</span><span 执行SQL语句插入</span>
<span 35</span>         <span $sql_add</span>="EXEC [V3].[dbo].[V3_teacher] ".<span $tidid</span>.",'".<span $tname</span>."', '".<span $tage</span>."', '".<span $tsex</span>."', '".<span $tcount</span>."', '".<span $tpwd</span>."', '".<span $tsuper</span>."','".<span $age</span>."','".<span $tel</span>."','".<span $address</span>."'"<span ;
</span><span 36</span>         <span $result_add</span> = mssql_query(<span $sql_add</span><span );
</span><span 37</span>         <span if</span>(<span $result_add</span><span )
</span><span 38</span>             {<span echo</span> "添加成功!"<span ;}
</span><span 39</span>         <span else</span> 
<span 40</span>             {<span echo</span> "sql出错!"<span ;}    
</span><span 41</span> <span     }
</span><span 42</span>     <span else</span>
<span 43</span> <span     {
</span><span 44</span>         <span //</span><span 报错并终止</span>
<span 45</span>         <span echo</span> ("两次密码不对"<span );
</span><span 46</span>         <span exit</span><span ();
</span><span 47</span> <span     }
</span><span 48</span> }

老师删减老师(权限限制)

<span  1</span> <span //</span><span POST传递信息</span>
<span  2</span> <span if</span>(<span isset</span>(<span $_POST</span>['delsub'<span ]))
</span><span  3</span> <span {
</span><span  4</span> <span     sql();
</span><span  5</span>     <span $tid</span>=<span $_POST</span>['id'<span ];
</span><span  6</span>     <span $sql</span>="DELETE FROM [V3].[dbo].[teacher] where [tid]=".<span $tid</span>.""<span ;
</span><span  7</span>     <span $result</span> = mssql_query(<span $sql</span><span );
</span><span  8</span>     <span if</span>(<span $result</span><span )
</span><span  9</span>         {<span echo</span> "删除成功"<span ;}
</span><span 10</span>     <span else</span>
<span 11</span>         {<span echo</span> "SQL出错!"<span ;}
</span><span 12</span> }

老师添加课程

<span  1</span> <span //</span><span POST传递信息</span>
<span  2</span> <span if</span>(<span isset</span>(<span $_POST</span>['addclass'<span ]))
</span><span  3</span> <span {
</span><span  4</span> <span     sql();
</span><span  5</span>     <span //</span><span POST传递信息</span>
<span  6</span>     <span $tid</span>=<span $_POST</span>['id'<span ];
</span><span  7</span>     <span $cname</span>=<span $_POST</span>['name'<span ];
</span><span  8</span>     <span //</span><span SQL语句插入</span>
<span  9</span>     <span $sql</span>="INSERT INTO [V3].[dbo].[class] ([sid], [tid], [cname],[score],[cid]) VALUES (0, ".<span $tid</span>.", '".<span $cname</span>."',999,".<span rand</span>(1,999).")"<span ;
</span><span 10</span>     <span $result</span> = mssql_query(<span $sql</span><span );
</span><span 11</span>     <span if</span>(<span $result</span><span )
</span><span 12</span>         {<span echo</span> "创建课程成功"<span ;}
</span><span 13</span>     <span else</span>
<span 14</span>         {<span echo</span> "SQL出错!"<span ;}
</span><span 15</span> }

老师查看选课情况

 

<span  1</span> <span if</span>(<span $_GET</span>['action']=='list'<span )
</span><span  2</span> <span {
</span><span  3</span>     <span //</span><span cookie传递tid</span>
<span  4</span>     <span $id</span>=<span $_COOKIE</span>["uid"<span ];
</span><span  5</span> <span     sql();
</span><span  6</span>     <span //</span><span SQL语句取得编号tid老师以及默认学生sid=0,得到课名cname和课号cid</span>
<span  7</span>     <span $sql_class</span>="SELECT * FROM [V3].[dbo].[class] where [tid]=".<span $id</span>." AND [sid] = 0"<span ;
</span><span  8</span>     <span $result_class</span> = mssql_query(<span $sql_class</span><span );    
</span><span  9</span>     <span $i</span>=0;<span //</span><span 保存有多少行</span>
<span 10</span>     <span while</span> (<span $row</span> = mssql_fetch_array(<span $result_class</span>,<span  MSSQL_ASSOC)) 
</span><span 11</span> <span     {
</span><span 12</span>         <span $class_id</span>[<span $i</span>]=<span $row</span>['cid'<span ];
</span><span 13</span>         <span $class_name</span>[<span $i</span>]=<span $row</span>['cname'<span ];
</span><span 14</span>         <span $i</span>++<span ;
</span><span 15</span> <span     }
</span><span 16</span>     <span //</span><span SQL语句通过tid和cid得到有多少学生选课</span>
<span 17</span>     <span for</span>(<span $a</span>=0;<span $a</span><<span $i</span>;<span $a</span>++<span )
</span><span 18</span> <span     {
</span><span 19</span>         <span $sql_num</span>[<span $a</span>]="SELECT * FROM [V3].[dbo].[class] where [tid]=".<span $id</span>." AND [cid] = ".<span $class_id</span>[<span $a</span>].""<span ;
</span><span 20</span>         <span $result_num</span>[<span $a</span>]= mssql_query(<span $sql_num</span>[<span $a</span><span ]);
</span><span 21</span>         <span $class_num</span>[<span $a</span>]=mssql_num_rows(<span $result_num</span>[<span $a</span><span ]);
</span><span 22</span> <span     }
</span><span 23</span>     <span //</span><span 保存字段中文含义</span>
<span 24</span>     <span $arrname</span>[0]='课号'<span ;
</span><span 25</span>     <span $arrname</span>[1]='课名'<span ;
</span><span 26</span>     <span $arrname</span>[2]='选课人数'<span ;
</span><span 27</span>         <span /*</span><span ******************
</span><span 28</span> <span                 HTML表格输出
</span><span 29</span> <span         ******************</span><span */</span>
<span 30</span>     <span echo</span> "<table border='1' >\n"<span ;
</span><span 31</span>     <span echo</span> "\t<tr><td colspan='3' align='center'>老师号:".<span $id</span>."</td></tr>\n"<span ;
</span><span 32</span>     <span echo</span> "\t<tr>\n"<span ;
</span><span 33</span>     <span //</span><span 有3列</span>
<span 34</span>     <span for</span>(<span $num</span>=0;<span $num</span><3;<span $num</span>++<span )
</span><span 35</span> <span     {
</span><span 36</span>         <span echo</span> "\t\t<td>".<span $arrname</span>[<span $num</span>]."</td>\n"<span ;
</span><span 37</span> <span     }
</span><span 38</span>     <span echo</span> "\t</tr>\n"<span ;
</span><span 39</span>     <span for</span>(<span $a</span>=0;<span $a</span><<span $i</span>;<span $a</span>++<span )
</span><span 40</span> <span     {
</span><span 41</span>         <span //</span><span 删去sid为0的</span>
<span 42</span>         <span $class_num</span>[<span $a</span>]=<span $class_num</span>[<span $a</span>]-1<span ;
</span><span 43</span>         <span echo</span> "\t<tr>\n"<span ;
</span><span 44</span>             <span echo</span> '<td>'.<span $class_id</span>[<span $a</span>].'</td>'<span ;
</span><span 45</span>             <span echo</span> '<td>'.<span $class_name</span>[<span $a</span>].'</td>'<span ;
</span><span 46</span>             <span echo</span> '<td>'.<span $class_num</span>[<span $a</span>].'</td>'<span ;
</span><span 47</span>         <span echo</span> "\t</tr>\n"<span ;
</span><span 48</span> <span     }
</span><span 49</span>     <span echo</span> "</table>\n"<span ;
</span><span 50</span> <span }
</span><span 51</span> ?>

老师删减课程

<span  1</span> <span //</span><span POST传递信息</span>
<span  2</span> <span if</span>(<span isset</span>(<span $_POST</span>['delclass'<span ]))
</span><span  3</span> <span {
</span><span  4</span> <span     sql();
</span><span  5</span>     <span //</span><span POST传递信息</span>
<span  6</span>     <span $cid</span>=<span $_POST</span>['cid'<span ];
</span><span  7</span>     <span //</span><span SQL进行删减操作</span>
<span  8</span>     <span $sql</span>="DELETE FROM [V3].[dbo].[class] where [cid]=".<span $cid</span>.""<span ;
</span><span  9</span>     <span $result</span> = mssql_query(<span $sql</span><span );
</span><span 10</span>     <span if</span>(<span $result</span><span )
</span><span 11</span>         {<span echo</span> "删除课程成功"<span ;}
</span><span 12</span>     <span else</span>
<span 13</span>         {<span echo</span> "SQL出错!";}

老师查看成绩

<span  1</span> <span //</span><span GET传递信息</span>
<span  2</span> <span if</span>(<span $_GET</span>['action']=='show'<span )
</span><span  3</span> <span {
</span><span  4</span> <span     sql();
</span><span  5</span>     <span //</span><span cookie传输tid</span>
<span  6</span>     <span $id</span>=<span $_COOKIE</span>["uid"<span ];
</span><span  7</span>     <span //</span><span SQL语句通过tid取得课号cid</span>
<span  8</span>     <span $sql_t</span>="SELECT * FROM [V3].[dbo].[class] where [sid]=0 AND [tid] = ".<span $id</span>.""<span ;
</span><span  9</span>     <span $result_t</span> = mssql_query(<span $sql_t</span><span );
</span><span 10</span>     <span $i</span>=0;<span //</span><span 保存老师有多少课程</span>
<span 11</span>     <span while</span> (<span $row</span> = mssql_fetch_array(<span $result_t</span>,<span  MSSQL_ASSOC)) 
</span><span 12</span> <span     {
</span><span 13</span>         <span $t_cid</span>[<span $i</span>]=<span $row</span>['cid'<span ];
</span><span 14</span>         <span $t_cname</span>[<span $i</span>]=<span $row</span>['cname'<span ];    
</span><span 15</span>         <span $i</span>++<span ;
</span><span 16</span> <span     }
</span><span 17</span>     <span //</span><span 将cid,sid,score存入数组</span>
<span 18</span>     <span for</span>(<span $a</span>=0;<span $a</span><<span $i</span>;<span $a</span>++<span )
</span><span 19</span> <span     {
</span><span 20</span>         <span //</span><span 通过cid找到选课了的学生</span>
<span 21</span>         <span $sql_t_s</span>="SELECT * FROM [V3].[dbo].[class] where [cid]=".<span $t_cid</span>[<span $a</span>]." AND [tid] = ".<span $id</span>.""<span ;
</span><span 22</span>         <span $result_t_s</span> = mssql_query(<span $sql_t_s</span><span );
</span><span 23</span>         <span $ii</span>=0;<span //</span><span 保存每个课程的学生人数</span>
<span 24</span>         <span while</span>(<span $row_ready</span> = mssql_fetch_array(<span $result_t_s</span>,<span  MSSQL_ASSOC))
</span><span 25</span> <span         {
</span><span 26</span>             <span $t_sid</span>[<span $a</span>][<span $ii</span>]=<span $row_ready</span>['sid'<span ];
</span><span 27</span>             <span $t_score</span>[<span $a</span>][<span $ii</span>]=<span $row_ready</span>['score'<span ];
</span><span 28</span>             <span $ii</span>++<span ;
</span><span 29</span> <span         }
</span><span 30</span>         <span $num</span>[<span $a</span>]=<span $ii</span>;<span //</span><span 把每个课程的人数存到数组里面</span>
<span 31</span> <span     }
</span><span 32</span>     <span //</span><span 通过sid找到sname</span>
<span 33</span>     <span for</span>(<span $b</span>=0;<span $b</span><<span $i</span>;<span $b</span>++<span )
</span><span 34</span> <span     {
</span><span 35</span>         <span for</span>(<span $c</span>=0;<span $c</span><<span $num</span>[<span $b</span>];<span $c</span>++<span )
</span><span 36</span> <span         {
</span><span 37</span>             <span //</span><span 通过cid找到选课了的学生</span>
<span 38</span>             <span $sql_sn</span>="SELECT * FROM [V3].[dbo].[V3_student] where [sid]=".<span $t_sid</span>[<span $b</span>][<span $c</span>].""<span ;
</span><span 39</span>             <span $result_sn</span> = mssql_query(<span $sql_sn</span><span );
</span><span 40</span>             <span while</span>(<span $row_sn</span> = mssql_fetch_array(<span $result_sn</span>,<span  MSSQL_ASSOC))
</span><span 41</span> <span             {
</span><span 42</span>                 <span $t_sname</span>[<span $b</span>][<span $c</span>]=<span $row_sn</span>['sname'<span ];
</span><span 43</span> <span             }
</span><span 44</span> <span         }
</span><span 45</span> <span     }    
</span><span 46</span>     <span //</span><span 列出老师的课程</span>
<span 47</span>     <span if</span>(<span $_GET</span>['cid']=='0'<span )
</span><span 48</span> <span     {
</span><span 49</span>         <span for</span>(<span $dd</span>=0;<span $dd</span><<span $i</span>;<span $dd</span>++<span )
</span><span 50</span> <span         { 
</span><span 51</span>                     <span echo</span> "<a href='score.php?action=show&cid=".<span $t_cid</span>[<span $dd</span>]."'>查看__".<span $t_cname</span>[<span $dd</span>]."__课程情况!</a><br>"<span ;        
</span><span 52</span> <span         }
</span><span 53</span> <span     }
</span><span 54</span>     <span for</span>(<span $ddd</span>=0;<span $ddd</span><<span $i</span>;<span $ddd</span>++<span )
</span><span 55</span> <span     {
</span><span 56</span>         <span if</span>(<span $_GET</span>['cid']==<span $t_cid</span>[<span $ddd</span><span ])
</span><span 57</span> <span         {
</span><span 58</span>             <span //</span><span 保存字段中文含义</span>
<span 59</span>             <span $arrname</span>[0]='课号'<span ;
</span><span 60</span>             <span $arrname</span>[1]='课名'<span ;
</span><span 61</span>             <span $arrname</span>[2]='学生号'<span ;
</span><span 62</span>             <span $arrname</span>[3]='学生名'<span ;
</span><span 63</span>             <span $arrname</span>[4]='成绩'<span ;
</span><span 64</span>             <span /*</span><span ******************
</span><span 65</span> <span                     HTML表格输出
</span><span 66</span> <span             ******************</span><span */</span>
<span 67</span>             <span echo</span> "<table border='1' >\n"<span ;
</span><span 68</span>             <span echo</span> "\t<tr>\n"<span ;
</span><span 69</span>             <span //</span><span 5列</span>
<span 70</span>             <span for</span>(<span $num5</span>=0;<span $num5</span><5;<span $num5</span>++<span )
</span><span 71</span> <span             {
</span><span 72</span>                 <span echo</span> "\t\t<td>".<span $arrname</span>[<span $num5</span>]."</td>\n"<span ;
</span><span 73</span> <span             }
</span><span 74</span>             <span echo</span> "\t</tr>\n"<span ;
</span><span 75</span>             
<span 76</span>                 <span for</span>(<span $e</span>=0;<span $e</span> < <span $num</span>[ <span $ddd</span> ];<span $e</span>++<span )
</span><span 77</span> <span                 {
</span><span 78</span>                     <span if</span>(<span $t_score</span>[<span $ddd</span>][<span $e</span>]=="999"<span )
</span><span 79</span> <span                     {
</span><span 80</span>                         <span $t_score</span>[<span $ddd</span>][<span $e</span>]="未上传成绩"<span ;
</span><span 81</span> <span                     }
</span><span 82</span>                     <span if</span>(<span $t_sid</span>[<span $ddd</span>][<span $e</span>]=='0'<span )
</span><span 83</span> <span                     {
</span><span 84</span>                         <span //</span><span 不显示默认为0的学生</span>
<span 85</span>                         <span continue</span><span ;
</span><span 86</span> <span                     }
</span><span 87</span>                     <span //</span><span 输出内容</span>
<span 88</span>                     <span echo</span> "\t<tr>\n"<span ;
</span><span 89</span>                         <span echo</span> '<td>'.<span $t_cid</span>[<span $ddd</span>].'</td>'<span ;
</span><span 90</span>                         <span echo</span> '<td>'.<span $t_cname</span>[<span $ddd</span>].'</td>'<span ;
</span><span 91</span>                         <span echo</span> '<td>'.<span $t_sid</span>[<span $ddd</span>][<span $e</span>].'</td>'<span ;
</span><span 92</span>                         <span echo</span> '<td>'.<span $t_sname</span>[<span $ddd</span>][<span $e</span>].'</td>'<span ;
</span><span 93</span>                         <span echo</span> '<td>'.<span $t_score</span>[<span $ddd</span>][<span $e</span>].'</td>'<span ;
</span><span 94</span>                     <span echo</span> "\t</tr>\n"<span ;
</span><span 95</span> <span                 }
</span><span 96</span>             <span echo</span> "</table>\n"<span ;
</span><span 97</span> <span         }
</span><span 98</span> <span     }
</span><span 99</span> }

老师上传成绩

<span> <span if>(<span isset>(<span>['up'<span><span> <span><span> <span sql><span>     <span><span cookie>
<span>     <span>=<span>["uid"<span><span>     <span><span post>
<span>     <span>=<span>['cid'<span><span>     <span><span>
<span>     <span>="SELECT * FROM [V3].[dbo].[class] where [cid]=".<span>." AND [tid] = ".<span>.""<span><span>     <span> = mssql_query(<span><span><span>     <span>=0;<span><span>
<span>     <span while> (<span> = mssql_fetch_array(<span>,<span mssql_assoc><span> <span><span>         <span>[<span>]=<span>['score'<span><span>         <span>[<span>]=<span>['sid'<span><span>         <span>++<span><span> <span><span>     <span for>(<span>=0;<span>;<span>++<span><span> <span><span>         <span if>(<span>[<span>]=='0'<span><span> <span><span>             <span><span>
<span>             <span continue><span><span> <span><span>         <span><span>
<span>         <span if>(<span is_numeric>(<span>["sid_<span>[<span>]"<span><span> <span><span>             <span><span>
<span>             <span if>(<span>["sid_<span>[<span>]"]</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn