ホームページ >バックエンド開発 >PHPチュートリアル >Sql Server 2008をベースにした分散データベースの実践(5)_PHPチュートリアル

Sql Server 2008をベースにした分散データベースの実践(5)_PHPチュートリアル

WBOY
WBOYオリジナル
2016-07-13 17:16:59870ブラウズ

プログラミング

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

Index.php——インターフェースを選択し、生徒と教師を登録します

sql_ini.php—SQL 構成ファイル

./student————学生の舞台裏

./admin————先生の舞台裏

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

./学生

cookie.php————クッキージャンプファイル

index1.php——バックエンドインターフェース

login.php————ログインインターフェース

loginout.php————Cookieログアウト処理

main.php————メインインターフェース

menu.php————バックエンドメニュー

sclass.php————学生のコース選択情報を表示します

score.php-————生徒のスコアを表示します

sinfo.php————表示*

sql_ini.php—SQL 設定ファイル

up.php——バックエンドフォーム処理ファイル

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

./管理者

class.php————教師コース情報を表示します

cookie.php————クッキージャンプファイル

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 $_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>         <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>]"]<=100&&<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></span>
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。