Skip to content

Commit 7337408

Browse files
committed
add match mod
1 parent f46ab36 commit 7337408

File tree

10 files changed

+338
-4
lines changed

10 files changed

+338
-4
lines changed

match/add.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
header('Content-type:text/html;charset=utf-8');
3+
$from =<<<HTML
4+
<form method="post" action="doAdd.php">
5+
选手1<input name="player1" /><br/>
6+
选手2<input name="player2" /><br/>
7+
比赛时间<input name="time" /><br/>
8+
比赛结果<input name="result" /><br/>
9+
比赛地点<input name="place" /><br/>
10+
<input type="submit" />
11+
</form>
12+
HTML;
13+
14+
echo $from;

match/conn.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
$uname = "root";
3+
$host = "127.0.0.1:3306";
4+
$pwd = "root";
5+
6+
$link = mysql_connect($host,$uname,$pwd);
7+
mysql_query("set names `utf8");
8+
mysql_query('use `match');
9+
?>

match/del.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
require('conn.php');
3+
$sql = 'delete from select_match where match_id='.$_GET['matchId'];
4+
$res = mysql_query($sql);
5+
if(!$res){
6+
echo '删除失败!';
7+
echo '<br/>';
8+
echo mysql_errno();
9+
die();
10+
}else{
11+
header('Location: detail.php');
12+
}

match/detail.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
header('Content-Type:text/html;charset=utf-8');
3+
require('conn.php');
4+
$sql = 'select match_id,s1.stu_name p1,s2.stu_name p2,match_time `time`,match_result as `result` from select_match'.
5+
' left join select_student as s1'.
6+
' on select_match.player_1 = s1.id'.
7+
' left join select_student as s2 '.
8+
' on select_match.player_2 = s2.id';
9+
10+
$res = mysql_query($sql);
11+
echo '<table border="1">';
12+
while ($row = mysql_fetch_assoc($res)) {
13+
echo "<tr><td>{$row['p1']}</td><td>{$row['p2']}</td><td>{$row['time']}</td><td>{$row['result']}</td><td><a href='del.php?matchId={$row['match_id']}'>删除</a></td><td><a href='mod.php?id={$row['match_id']}'>修改</a></td></tr>";
14+
}
15+
echo '</table>';

match/doAdd.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
header('Content-type:text/html;charset=utf-8');
3+
$p1= $_POST['player1'];
4+
$p2 = $_POST['player2'];
5+
$time = $_POST['time'];
6+
$res = $_POST['result'];
7+
$place = $_POST['place'];
8+
9+
require('conn.php');
10+
$result = mysql_query("insert into select_match (player_1,player_2,match_time,match_result,match_address) values( '$p1','$p2','$time','$res','$place')");
11+
if(!$result){
12+
echo '添加失败!';
13+
echo '<br/>';
14+
echo mysql_error();
15+
die();
16+
}else{
17+
header('Location:index.php');
18+
}

match/doMod.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
header('Content-Type:text/html;charset=utf-8');
3+
$id = $_POST['id'];
4+
$sql = 'update select_match set';
5+
if(!isset($id)){
6+
echo '缺少参数';
7+
die();
8+
}
9+
if(isset($_POST['p1'])){
10+
$sql .= " player_1={$_POST['p1']},";
11+
}
12+
if(isset($_POST['p2'])){
13+
$sql.=" player_2={$_POST['p2']},";
14+
}
15+
if(isset($_POST['time'])){
16+
$sql .=" match_time='{$_POST['time']}',";
17+
}
18+
if(isset($_POST['result'])){
19+
$sql .=" match_result='{$_POST['result']}',";
20+
}
21+
if (isset($_POST['place'])) {
22+
$sql .=" match_address={$_POST['place']}";
23+
}
24+
$sql .= " where match_id={$_POST['id']}";
25+
26+
require('conn.php');
27+
if (!mysql_query($sql)) {
28+
echo '修改失败!';
29+
echo '<br/>';
30+
echo mysql_errno();
31+
echo '<br/>';
32+
echo mysql_error().'-->'.$sql;
33+
die();
34+
}
35+
header('Location:detail.php');

match/index.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
header('Content-Type:text/html;charset=utf-8');
3+
require("conn.php");
4+
//mysql_query('use `match`');
5+
6+
$res = mysql_query('select * from select_match');
7+
echo '<table border='1'>';
8+
echo '<tr><th>match_id</th><th>player1</th><th>player2</th><th>match_time</th><th>match_result</th><th>match_place</th></tr>';
9+
while($row = mysql_fetch_assoc($res)){
10+
echo "<tr><td>{$row['match_id']}</td><td>{$row['player_1']}</td><td>{$row['player_2']}</td><td>{$row['match_time']}</td><td>{$row['match_result']}</td><td>{$row['match_address']}</td></tr>";
11+
}
12+
echo '</table>';
13+
echo '<a href="detail.php">查看详细</a>';
14+
echo '<br>';
15+
echo '<a href="add.php">新增</a>';
16+
echo '<br>';
17+

match/mod.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
header('Content-Type:text/html;charset=utf-8');
3+
$id = $_GET['id'];
4+
require('conn.php');
5+
$res = mysql_query("select * from select_match where match_id=$id");
6+
if(!$res){
7+
echo '查询失败!<br />';
8+
echo mysql_errno().':'.mysql_error();
9+
die();
10+
}
11+
$row = mysql_fetch_assoc($res);
12+
$str =<<<HTML
13+
<form method="post" action="doMod.php">
14+
选手1:<input name="p1" value="{$row['player_1']}" /><br/>
15+
选手2:<input name="p2" value="{$row['player_2']}" /><br/>
16+
比赛时间:<input name="time" value="{$row['match_time']}" /><br />
17+
结果:<input name="result" value="{$row['match_result']}" /><br />
18+
地点:<input name="place" value="{$row['match_address']}" /><br />
19+
<input type="hidden" name="id" value="{$row['match_id']}" />
20+
<input type="submit" />
21+
</form>
22+
HTML;
23+
24+
echo $str;

new/DB.class.php

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?php
2+
class DB{
3+
private $host;
4+
private $port;
5+
private $user;
6+
private $pass;
7+
private $dbName;
8+
private $charset;
9+
private $link;
10+
private $last_sql;
11+
12+
/**
13+
* [__construct description]
14+
* @param 数组形式的属性
15+
*/
16+
public function __construct($param = array()){
17+
$this->host = isset($param['host'])?'127.0.01.1':$param['host'];
18+
$this->port = iseet($param['port'])?'3306':$param['port'];
19+
$this->user = iseet($param['user'])?'root':$param['user'];
20+
$this->pass = iseet($param['pass'])?'root':$param['pass'];
21+
$this->charset = isset($param['charset'])?'utf8':$param['charset'];
22+
23+
}
24+
25+
/**
26+
* 连接数据库
27+
* @return [type]
28+
*/
29+
private function connection(){
30+
if (!mysql_connect("$this->host:$this->port",$this->user,$this->pass)) {
31+
echo '数据库连接失败!<br>';
32+
echo mysql_errno().'<br>';
33+
echo mysql_error().'<br/>';
34+
die();
35+
}
36+
}
37+
38+
/**
39+
* 设置字符集
40+
*/
41+
private function setCharset(){
42+
if (mysql_query("set names $this->charset")) {
43+
echo '设置字符集失败!<br>';
44+
echo mysql_errno().'<br>';
45+
echo mysql_error().'<br/>';
46+
die();
47+
}
48+
}
49+
50+
/**
51+
* 设置使用数据库
52+
*/
53+
private function setDB(){
54+
if (mysql_query("use $this->dbName")) {
55+
echo '设置字符集失败!<br>';
56+
echo mysql_errno().'<br>';
57+
echo mysql_error().'<br/>';
58+
die();
59+
}
60+
}
61+
62+
/**
63+
* 根据传入SQL 返回记录
64+
*
65+
*
66+
* @param 执行的
67+
*
68+
* @return 查询得到的资源
69+
*/
70+
public function query($sql){
71+
$this->last_sql = $sql;
72+
if (!$res = mysql_query($sql)) {
73+
echo "SQL执行失败<br>";
74+
echo "出错的SQL是$sql<br>";
75+
echo mysql_errno().'<br>';
76+
echo mysql_error().'<br/>';
77+
die();
78+
}else{
79+
return $res;
80+
}
81+
}
82+
83+
/**
84+
* [fetchAll description]
85+
* @param [type]
86+
* @return 包含查询结果集的二维数组
87+
*/
88+
public function fetchAll($sql){
89+
if ($res = $this->query($sql)) {
90+
$rows = array();
91+
while ($row = mysql_fetch_assoc($res)) {
92+
$rows[] = $row;
93+
}
94+
mysql_free_result($res);
95+
return $rows;
96+
}else{
97+
return false;
98+
}
99+
}
100+
101+
/**
102+
* 获取查询结果中第一条记录
103+
* @param SQL
104+
*
105+
* @return 第一条记录
106+
*/
107+
public function fetchRow($sql){
108+
if ($res = $this->query($sql)) {
109+
$row = mysql_fetch_assoc($res);
110+
mysql_free_result($res);
111+
return $row;
112+
}
113+
114+
}
115+
116+
117+
/**
118+
* 获取查询结果集中第一条记录的第一个字段值
119+
* @param 待执行的SQL
120+
* @return 字段值得
121+
*/
122+
public function fetchColum($sql){
123+
if ($res = $this->query($sql)) {
124+
if($row = mssql_fetch_assoc($res)){
125+
mysql_free_result($res);
126+
return $row[0];
127+
}else{
128+
return false;
129+
}
130+
}else{
131+
return false;
132+
}
133+
}
134+
135+
/**
136+
* 序列化时 调用 指定哪些属性需要被序列化
137+
* @return array
138+
*/
139+
public function __sleep(){
140+
return array('host','port','user','pass','charset','dbName');
141+
}
142+
143+
/**
144+
* f反序列化时调用
145+
*‘
146+
* 用于对对象属性的初始化
147+
*/
148+
public function __wakeup(){
149+
$this->connectionl();
150+
$this->setCharset();
151+
$this->setDB();
152+
}
153+
}

new/MySQLDB.php

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ private function setDB(){
4848
echo 'DBFAIL 3<br>';
4949
echo mysql_errno(),mysql_error();
5050
die();
51-
}
51+
}
5252
}
5353

5454
// private function exeSQL(){
@@ -74,8 +74,6 @@ private function exeSQL(){
7474
}
7575
}
7676

77-
78-
7977
public function fetchAll(){
8078
if($res = $this->exeSQL()){
8179
$rows = array();
@@ -88,8 +86,47 @@ public function fetchAll(){
8886
return false;
8987
}
9088
}
89+
90+
/**
91+
*
92+
*
93+
* 利用一条sql 返回符合条件的第一条记录
94+
*
95+
*@param $sql 待执行的sql
96+
*
97+
*@return array 一堆数组
98+
*/
99+
100+
public function fetchRow(){
101+
$res = $this->exeSQL();
102+
if($res){
103+
$row = mysql_fetch_assoc($res);
104+
mysql_free_result($res);
105+
return $row;
106+
}else{
107+
return false;
108+
}
109+
}
110+
111+
/**
112+
*利用一条sql 返回符合条件的第一条记录第一个字段的值
113+
*@param $sql 待执行的sql
114+
*@return $row[0] 记录中第一个字段值
115+
*/
116+
public function fetchColum($sql){
117+
if ($res = $this->exeSQL()) {
118+
if ($row = mysql_fetch_assoc($res)) {
119+
mysql_free_result($res);
120+
return $row[0];
121+
}else{
122+
return false;
123+
}
124+
125+
}else{
126+
return false;
127+
}
128+
}
91129
}
92-
//echo 'aaaa';
93130
$db = new DB();
94131
echo '<pre>';
95132
//var_dump($db);

0 commit comments

Comments
 (0)