标签:
题目要求:
1,查找数据库资料,分页显示,
2,可以增、删、改,
3,可以按条件查找。
main.php
1 <?php
2 include("./init.inc.php");
3
4 include("../DBDA.class.php");
5 $db = new DBDA();
6
7 include("page.class.php");
8
9 //$_GET["name"];
10 //$_GET["km"];
11 //条件
12 $tj1=" 1=1 ";
13 $tj2=" 1=1 ";
14 if(!empty($_GET["name"]))
15 {
16 $tj1=" name like ‘%{$_GET[‘name‘]}%‘ ";
17 }
18 if(!empty($_GET["km"]))
19 {
20 $tj2 =" kemu = ‘{$_GET[‘km‘]}‘ ";
21 }
22 $tj=" where ".$tj1." and ".$tj2;
23
24 //查总数
25 $sqltl = "select count(*) from timu ".$tj;
26 $total = $db->StrQuery($sqltl);
27 $page = new Page($total,3);
28
29
30 //查数据,做表格
31 $sql = "select * from timu ".$tj.$page->limit;
32 $attr = $db->query($sql);
33 $fpage = $page->fpage();
34
35 //科目
36 $sqlkm="select * from kemu";
37 $kemu = $db->query($sqlkm);
38
39 //注册变量
40 $smarty->assign("str",$attr);
41 $smarty->assign("km",$kemu);
42 $smarty->assign("fpage",$fpage);
43
44 $smarty->display("./templates/main.html");
45
46 ?>
main.html
1 <body >
2 <h1 align="center">这是主页面</h1><br />
3
4 <div>
5 <form action="main.php" method="get">
6 按条件查找:
7 题目<input type="text" name="name" />
8 科目:
9 <select name="km">
10 <{foreach $km as $vv}>
11 <option value="<{$vv[1]}>"><{$vv[0]}></option>
12 <{/foreach}>
13 </select>
14
15 <input type="submit" value="查找" /><br />
16 </form>
17 </div><br />
18
19 <table border="1px" cellpadding="0" cellspacing="0" width="600px" bgcolor="#99FF66">
20 <tr>
21 <td>题目名称</td>
22 <td>答案</td>
23 <td>所属科目</td>
24 <td>难度</td>
25 <td>类型</td>
26 <td>操作</td>
27 </tr>
28
29 <{foreach $str as $v}>
30 <tr>
31 <td><{$v[1]|truncate:6:"***"}></td>
32 <td><{$v[2]|color}></td>
33 <td><{$v[3]|kemu}></td>
34 <td><{$v[4]|nandu}></td>
35 <td><{$v[5]|type}></td>
36 <td>
37 <{text color=‘red‘ size=‘25px‘}>
38 <a href="update.php?code=<{$v[0]}>">更改</a>
39 <a href="delete.php?code=<{$v[0]}>">删除</a>
40 <{/text}>
41 </td>
42 </tr>
43 <{/foreach}>
44
45 </table><br />
46
47 <{$fpage}><br />
48
49
50 <form action="add.php" method="post">
51 <input type="submit" value="添加数据"/>
52 </form>
53
54 </body>
55 </html>
add.php
<?php
include("./init.inc.php");
include("../DBDA.class.php");
$db = new DBDA();
$smarty->display("./templates/add.html");
add.html
1 <body>
2 <form action="xgchuli.php" method="post">
3 题目;<input type="text" name="timu" /><br />
4 答案:<br />
5 A,<input type="text" name="a" /><br />
6 B,<input type="text" name="b" /><br />
7 C,<input type="text" name="c" /><br />
8 D,<input type="text" name="d" /><br />
9 选择:<input type="text" name="xuanxiang"/><br /><br />
10
11 科目;<input type="text" name="kemu" /><br /><br />
12
13 难度;
14 <select name="nandu">
15
16 <option value="1">简单</option>
17
18 <option value="2">普通</option>
19
20 <option value="3">困难</option>
21
22 </select>
23 <br /> <br />
24
25 类型;<input type="text" name="type" /><br />
26 <input type="submit" value="更改" />
27 </form>
28
29 </body>
30 </html>
xgchuli.php
1 <?php
2 include("../DBDA.class.php");
3 $db = new DBDA();
4
5 $timu = $_POST["timu"];
6 $daan = $_POST["xuanxiang"];
7 $kemu = $_POST["kemu"];
8 $nandu = $_POST["nandu"];
9 $type = $_POST["type"];
10
11 $a = $_POST["a"];
12 $b = $_POST["b"];
13 $c = $_POST["c"];
14 $d = $_POST["d"];
15
16 $sql="insert into timu values(‘‘,‘{$timu}‘,‘{$daan}‘,‘{$kemu}‘,‘{$nandu}‘,‘{$type}‘)";
17
18 if($db->query($sql,1))
19 {
20 $sqlmax="select max(code) from timu";
21 $result = $db->query($sqlmax);
22 $tm = $result[0][0];
23
24 $sqla = "insert into xuanxiang values(‘‘,‘{$a}‘,‘A‘,‘{$tm}‘)";
25 $db->query($sqla,1);
26 $sqlb = "insert into xuanxiang values(‘‘,‘{$b}‘,‘B‘,‘{$tm}‘)";
27 $db->query($sqlb,1);
28 $sqlc = "insert into xuanxiang values(‘‘,‘{$c}‘,‘C‘,‘{$tm}‘)";
29 $db->query($sqlc,1);
30 $sqld = "insert into xuanxiang values(‘‘,‘{$d}‘,‘D‘,‘{$tm}‘)";
31 $db->query($sqld,1);
32
33 header("location:main.php");
34 }
35 else
36 {
37 echo "添加失败";
38 }
39
40 ?>
update.php
1 <?php
2 include("./init.inc.php");
3
4 include("../DBDA.class.php");
5 $db = new DBDA();
6
7 $code = $_GET["code"];
8
9 $sql = "select * from timu where code=$code";
10 $attr = $db->query($sql);
11
12 $smarty->assign("str",$attr);
13 $smarty->display("./templates/xg.html");
14
15 $sqld="delete from timu where code=$code";
16 $db->query($sqld,1);
17
18 ?>
xg.html
1 <body>
2 <form action="xgchuli.php" method="post">
3 题目;<input type="text" name="timu" value="<{$str[0][1]}>"/><br />
4 答案;<input type="text" name="daan" value="<{$str[0][2]}>"/><br />
5 科目;<input type="text" name="kemu" value="<{$str[0][3]}>"/><br />
6 难度;
7 <select name="nandu">
8 <{if $str[0][4]==1}>
9 <option value="1" selected="selected">简单</option>
10 <{else}>
11 <option value="1">简单</option>
12 <{/if}>
13
14 <{if $str[0][4]==2}>
15 <option value="2" selected="selected">普通</option>
16 <{else}>
17 <option value="2">普通</option>
18 <{/if}>
19
20 <{if $str[0][4]==3}>
21 <option value="3" selected="selected">困难</option>
22 <{else}>
23 <option value="3">困难</option>
24 <{/if}>
25 </select>
26 <br />
27 类型;<input type="text" name="type" value="<{$str[0][5]}>"/><br />
28 <input type="submit" value="更改" />
29 </form>
30
31
32 </body>
33 </html>
delete.php
1 <?php
2 include("../DBDA.class.php");
3 $db = new DBDA();
4
5 $code = $_GET["code"];
6
7 $sqlda="delete from xuanxiang where timu=$code";
8 $db->query($sqlda,1);
9
10 $sqld="delete from timu where code=$code";
11 if($db->query($sqld,1))
12 {
13 header("location:main.php");
14 }
15 else
16 {
17 echo "删除失败";
18 }
19
20 ?>
标签:
原文地址:http://www.cnblogs.com/wanlibingfeng/p/5568507.html