0%

[技能檢定]題組一 步驟12 快速套用所有功能的列表及編輯功能

列表功能的部份除了欄位有差異外,程式的邏輯是一樣的,因此可以參考 ./back/title.php 中的程式碼片段來快速套用到其他的功能中,因此我們可以直接複製 ./back/title.php ,將檔名改成各個功能的名稱,再進行欄位的修改,即可快速套用。

由於我們在 /api/db.php 中有針對網址參數做了一個資料表物件的設定,因此在後台進行各個功能的資料表動作時,可以統一取用$DB這個變數,即代表該資料表物件。
/api/db.php

1
2
3
4
5
6
7
8
9
10
11
12
13
//判斷網址參數中是否有do
if(isset($_GET['do'])){

//再判斷網址參數是否有對應的資料表物件存在
if(isset(${ucfirst($_GET['do'])})){

//將資料表物件指定給$DB這個變數
$DB=${ucfirst($_GET['do'])};
}
}else{
//預設$DB變數為$Title
$DB=$Title;
}

AD-動態文字廣告管理

/back/ad.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<div style="width:99%; height:87%; margin:auto; overflow:auto; border:#666 1px solid;">
<p class="t cent botli">動態文字廣告管理</p>
<form method="post" action="./api/edit.php">
<table width="100%" style="text-align: center">
<tr class="yel">
<td width="80%">動態文字廣告</td>
<td width="10%">顯示</td>
<td width="10%">刪除</td>
</tr>
<?php
//撈出所有的資料
$rows=$DB->all();
//使用迴圈來取出每一筆資料
foreach($rows as $row){
?>
<tr>
<td>
<input type="text" name="text[]" style="width:90%" value="<?=$row['text'];?>">
<input type="hidden" name="id[]" value="<?=$row['id'];?>">
</td>
<td>
<input type="checkbox" name="sh[]" value="<?=$row['id'];?>" <?=($row['sh']==1)?'checked':'';?>>
</td>
<td>
<input type="checkbox" name="del[]" value="<?=$row['id'];?>">
</td>
</tr>
<?php } ?>
</table>
<table style="margin-top:40px; width:70%;">
<tr>
<input type="hidden" name="table" value="<?=$do;?>">
<td width="200px">
<input type="button" onclick="op('#cover','#cvr','./modal/<?=$do;?>.php?table=<?=$do;?>')" value="新增動態文字廣告">
</td>
<td class="cent">
<input type="submit" value="修改確定">
<input type="reset" value="重置">
</td>
</tr>
</table>
</form>
</div>

MVIM-動畫圖片管理

/back/mvim.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<div style="width:99%; height:87%; margin:auto; overflow:auto; border:#666 1px solid;">
<p class="t cent botli">動畫圖片管理</p>
<form method="post" action="./api/edit.php">
<table width="100%" style="text-align: center">
<tr class="yel">
<td width="70%">動畫圖片</td>
<td width="10%">顯示</td>
<td width="10%">刪除</td>
<td></td>
</tr>
<?php
$rows=$DB->all();
foreach($rows as $row){
?>
<tr>
<td>
<img src="./img/<?=$row['img'];?>" style="width:150px;height:100px">
<input type="hidden" name="id[]" value="<?=$row['id'];?>">
</td>
<td>
<input type="checkbox" name="sh[]" value="<?=$row['id'];?>" <?=($row['sh']==1)?'checked':'';?>>
</td>
<td>
<input type="checkbox" name="del[]" value="<?=$row['id'];?>">
</td>
<td>
<input type="button" onclick="op('#cover','#cvr','./modal/upload.php?table=<?=$do;?>&id=<?=$row['id'];?>')" value="更換動畫">
</td>
</tr>
<?php } ?>
</table>
<table style="margin-top:40px; width:70%;">
<tr>
<input type="hidden" name="table" value="<?=$do;?>">
<td width="200px">
<input type="button" onclick="op('#cover','#cvr','./modal/<?=$do;?>.php?table=<?=$do;?>')" value="新增動畫圖片">
</td>
<td class="cent">
<input type="submit" value="修改確定">
<input type="reset" value="重置">
</td>
</tr>
</table>
</form>
</div>

IMAGE-校園映像資料管理

校園映像資料功能要求要有分頁的功能,因此我們要加上關於分頁的相關程式碼

/back/image.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<div style="width:99%; height:87%; margin:auto; overflow:auto; border:#666 1px solid;">
<p class="t cent botli">校園映像資料管理</p>
<form method="post" action="./api/edit.php">
<table width="100%" style="text-align: center">
<tr class="yel">
<td width="70%">校園映像資料圖片</td>
<td width="10%">顯示</td>
<td width="10%">刪除</td>
<td></td>
</tr>
<?php
//建立分頁功能需要的參數及計算
$total=$DB->count();
$div=3;
$pages=ceil($total/$div);
$now=$_GET['p']??1;
$start=($now-1)*$div;

//根據分頁計算結果取出當前頁的資料
$rows=$DB->all(" limit $start,$div");
foreach($rows as $row){
?>
<tr>
<td>
<img src="./img/<?=$row['img'];?>" style="width:100px;height:68px">
<input type="hidden" name="id[]" value="<?=$row['id'];?>">
</td>
<td>
<input type="checkbox" name="sh[]" value="<?=$row['id'];?>" <?=($row['sh']==1)?'checked':'';?>>
</td>
<td>
<input type="checkbox" name="del[]" value="<?=$row['id'];?>">
</td>
<td>
<input type="button" onclick="op('#cover','#cvr','./modal/upload.php?table=<?=$do;?>&id=<?=$row['id'];?>')" value="更換動畫">
</td>
</tr>
<?php } ?>
</table>
<div class="cent">
<?php
//判斷是否有前一頁並建立前一頁的連結
if($now>1){
$prev=$now-1;
echo "<a href='?do=$do&p=$prev'> < </a>";
}

//建立每一頁的連結
for($i=1;$i<=$pages;$i++){
//判斷是否為當前頁,並給予不同的字型大小設定
$fontsize=($now==$i)?'24px':'16px';
echo "<a href='?do=$do&p=$i' style='font-size:$fontsize'> $i </a>";
}

//判斷是否有下一頁並建立下一頁的連結
if($now<$pages){
$next=$now+1;
echo "<a href='?do=$do&p=$next'> > </a>";
}
?>
</div>
<table style="margin-top:40px; width:70%;">
<tr>
<input type="hidden" name="table" value="<?=$do;?>">
<td width="200px">
<input type="button" onclick="op('#cover','#cvr','./modal/<?=$do;?>.php?table=<?=$do;?>')" value="新增校園映像資料圖片">
</td>
<td class="cent">
<input type="submit" value="修改確定">
<input type="reset" value="重置">
</td>
</tr>
</table>
</form>
</div>

NEWS-最新消息管理

/back/news.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<div style="width:99%; height:87%; margin:auto; overflow:auto; border:#666 1px solid;">
<p class="t cent botli">最新消息資料管理</p>
<form method="post" action="./api/edit.php">
<table width="100%" style="text-align: center">
<tr class="yel">
<td width="80%">最新消息資料內容</td>
<td width="10%">顯示</td>
<td width="10%">刪除</td>
</tr>
<?php
$total=$DB->count();
$div=5;
$pages=ceil($total/$div);
$now=$_GET['p']??1;
$start=($now-1)*$div;
$rows=$DB->all(" limit $start,$div");
foreach($rows as $row){
?>
<tr>
<td>
<textarea type="text" name="text[]" style="width:90%;height:60px"><?=$row['text'];?></textarea>
<input type="hidden" name="id[]" value="<?=$row['id'];?>">
</td>
<td>
<input type="checkbox" name="sh[]" value="<?=$row['id'];?>" <?=($row['sh']==1)?'checked':'';?>>
</td>
<td>
<input type="checkbox" name="del[]" value="<?=$row['id'];?>">
</td>
</tr>
<?php } ?>
</table>
<div class="cent">
<?php
if($now>1){
$prev=$now-1;
echo "<a href='?do=$do&p=$prev'> < </a>";
}
for($i=1;$i<=$pages;$i++){
$fontsize=($now==$i)?'24px':'16px';
echo "<a href='?do=$do&p=$i' style='font-size:$fontsize'> $i </a>";
}
if($now<$pages){
$next=$now+1;
echo "<a href='?do=$do&p=$next'> > </a>";
}
?>
</div>
<table style="margin-top:40px; width:70%;">
<tr>
<input type="hidden" name="table" value="<?=$do;?>">
<td width="200px">
<input type="button" onclick="op('#cover','#cvr','./modal/<?=$do;?>.php?table=<?=$do;?>')" value="新增最新消息資料">
</td>
<td class="cent">
<input type="submit" value="修改確定">
<input type="reset" value="重置">
</td>
</tr>
</table>
</form>
</div>

ADMIN-管理者管理

/back/admin.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<div style="width:99%; height:87%; margin:auto; overflow:auto; border:#666 1px solid;">
<p class="t cent botli">管理者帳號管理</p>
<form method="post" action="./api/edit.php">
<table width="100%" style="text-align: center">
<tr class="yel">
<td width="45%">帳號</td>
<td width="45%">密碼</td>
<td width="10%">刪除</td>
</tr>
<?php
$rows=$DB->all();
foreach($rows as $row){
?>
<tr>
<td>
<input type="text" name="acc[]" style="width:90%" value="<?=$row['acc'];?>">
</td>
<td>
<input type="password" name="pw[]" value="<?=$row['pw'];?>">
</td>
<td>
<input type="checkbox" name="del[]" value="<?=$row['id'];?>">
</td>
</tr>
<input type="hidden" name="id[]" value="<?=$row['id'];?>">
<?php } ?>
</table>
<table style="margin-top:40px; width:70%;">
<tr>
<input type="hidden" name="table" value="<?=$do;?>">
<td width="200px">
<input type="button" onclick="op('#cover','#cvr','./modal/<?=$do;?>.php?table=<?=$do;?>')" value="新增管理者帳號">
</td>
<td class="cent">
<input type="submit" value="修改確定">
<input type="reset" value="重置">
</td>
</tr>
</table>
</form>
</div>

/back/menu.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<div style="width:99%; height:87%; margin:auto; overflow:auto; border:#666 1px solid;">
<p class="t cent botli">選單管理</p>
<form method="post" action="./api/edit.php">
<table width="100%" style="text-align: center">
<tr class="yel">
<td width="30%">主選單名稱</td>
<td width="30%">選單連結網址</td>
<td width="10%">次選單數</td>
<td width="10%">顯示</td>
<td width="10%">刪除</td>
<td></td>
</tr>
<?php
$rows=$DB->all(['menu_id'=>0]);
foreach($rows as $row){
?>
<tr>
<td>
<input type="text" name="text[]" value="<?=$row['text'];?>">
</td>
<td>
<input type="text" name="href[]" value="<?=$row['href'];?>">
</td>
<td><?=$Menu->count(['menu_id'=>$row['id']]);?></td>
<td>
<input type="checkbox" name="sh[]" value="<?=$row['id'];?>" <?=($row['sh']==1)?'checked':'';?>>
</td>
<td>
<input type="checkbox" name="del[]" value="<?=$row['id'];?>">
</td>
<td>
<input type="button" value="編輯次選單" onclick="op('#cover','#cvr','./modal/submenu.php?table=<?=$do;?>&id=<?=$row['id'];?>')">
</td>
</tr>
<input type="hidden" name="id[]" value="<?=$row['id'];?>" >
<?php
}
?>
</table>
<table style="margin-top:40px; width:70%;">
<tr>
<input type="hidden" name="table" value="<?=$do;?>">
<td width="200px">
<input type="button" onclick="op('#cover','#cvr','./modal/<?=$do;?>.php?table=<?=$do;?>')" value="新增主選單">
</td>
<td class="cent">
<input type="submit" value="修改確定">
<input type="reset" value="重置">
</td>
</tr>
</table>
</form>
</div>