直接将全部查询结果同步

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
76
77
78
79
80
81
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>标题</title>
<style type="text/css">
table{
border: 1px solid black;
border-color:#F06;
padding:10px;
border-collapse:collapse;
}
table tr th{
border: 1px solid black;
border-color:#F06;
padding:10px;
border-collapse:collapse;
}
table tr td{
border: 1px solid black;
border-color:#F06;
padding:10px;
border-collapse:collapse;
}
</style>
</head>

<body>
<center>
<caption >
<p class="text">
自定义描述信息!
</p>
</caption>
<table>
<tr><th>显示的第一个字段名称</th><th>显示的第二个字段名称</th></tr>
<?php
//header("Content-Type:text/html;charset=utf-8");//设置页面字符编码
// 常量参数
define("DB_HOST", 'MySQL数据库连接地址');
define("DB_USER", 'MySQL用户名');
define("DB_PWD",'MySQL密码');
define("DB_NAME", 'MySQL库名');

// 第一步,连接数据库
$conn = mysql_connect('MySQL数据库连接地址','MySQL用户名','MySQL密码') or die('数据库连接失败,错误信息:'.mysql_error());

// 第二步,选择指定的数据库,设置字符集
mysql_select_db(DB_NAME,$conn) or die('数据库错误,错误信息:'.mysql_error());
mysql_query('SET NAMES UTF8') or die('字符集设置错误:'.mysql_error());

//新增数据
// $query = "INSERT INTO tk(name,email,point,regdate)
// VALUES('护士','hs@qq.com',67,NOW())";
// mysql_query($query) or die('新增错误:'.mysql_error());

// 修改数据
// $query = 'UPDATE tk SET point = 87 WHERE id = 7';
// @mysql_query($query) or die('修改错误:'.mysql_error());

//删除数据
// $query = 'DELETE FROM tk WHERE id = 7';
// @mysql_query($query) or die('删除错误:'.mysql_error());

// 显示数据

$query = 'SELECT * FROM 要查询的表 where 要查询的字段 like "%要查询的关键字%"';
// $query = 'SELECT * FROM 要查询的表';
$result = mysql_query($query) or die('SQL语句错误:'.mysql_error());

// 把结果集转换成数组赋值给$row,如果有数据为真
while(!!$row = mysql_fetch_array($result)){
echo"<tr><td>".$row["显示的第一个字段名称"]."</td><td>".$row["显示的第二个字段名称"]."</td><tr>";
}

mysql_close($conn);
?>
</table>
</center>
</body>
</html>

通过关键字查询结果后再进行同步

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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>标题</title>
<style type="text/css">
table{
border: 1px solid black;
border-color:#F06;
padding:10px;
border-collapse:collapse;
}
table tr th{
border: 1px solid black;
border-color:#F06;
padding:10px;
border-collapse:collapse;
}
table tr td{
border: 1px solid black;
border-color:#F06;
padding:10px;
border-collapse:collapse;
text-align:center;
}

.inputLine{
margin-right:10px;
}
.text_input{
display:inline-block;

padding:0 0 0 10px;
border:none;
outline:none;
border-radius:4px;
font-size:14px;
border:1px solid #dddddd;
box-sizing:border-box;
}
.search_btn {
background-color:#F06;
display:inline-block;
font-size:14px;
text-align:center;

vertical-align:middle;
color:#ffffff;
border-radius:4px;
border:none;
outline:none;
box-sizing:border-box;
cursor:pointer;
}
.search_btn:hover{
opacity:0.8;
}

.text{
width:100%;
padding: 0 15px;
box-sizing:border-box;
}
@media (min-width:900px) {
.container {
width:900px;
margin:0 auto;
}
.input_container{
width:900px;
}
}
@media (min-width:768px) {
.tips{
color:red;
font-size:16px;
margin-bottom:20px;
font-weight:bold;
}
.input_container{
margin:30px auto 30px auto;
display:flex;
align-items:center;
justify-content:center;
}
.container {
width:700px;
margin:0 auto;
}
.text_input{
width:350px;
height:40px;
line-height:40px;
}
.search_btn{
width:150px;
height:40px;
line-height:40px;
}
.input_container{
width:700px;
}
.text-wrapper{
padding:0 30px;
}
}
@media (max-width:767px) {
.text-wrapper{
padding:0 10px;
}
.tips{
color:red;
font-size:14px;
font-weight:bold;
margin-bottom:20px;
}
.input_container{
margin:30px auto 30px auto;
display:flex;
align-items:center;
justify-content:center;
/* padding:0 15px; */
}
.container {
width:100%;
margin:0 auto;
}
.text_input{
width:250px;
height:35px;
line-height:35px;
}
.search_btn{
width:60px;
height:35px;
line-height:35px;
}
}
table{
width:100%;
}
</style>
</head>

<body>
<form method="post" name="search" class="container">
<div class="input_container">
<div class="inputLine">
<input class="text_input" name="search" type="text" placeholder="请输入.."/>
</div>
<div>
<button class="search_btn">搜索</button>
</div>
</div>

<center class="text-wrapper">
<caption >
<p class="text">
自定义描述信息!
</p>
</caption>
<table class="table_wrapper">
<tr><th>显示的第一个字段名称</th><th>显示的第二个字段名称</th></tr>
<?php
header("Content-Type:text/html;charset=utf-8");//设置页面字符编码
// 常量参数
define("DB_HOST", 'MySQL数据库连接地址');
define("DB_USER", 'MySQL用户名');
define("DB_PWD",'MySQL密码');
define("DB_NAME", 'MySQL库名');

// 第一步,连接数据库
$conn = mysql_connect('MySQL数据库连接地址','MySQL用户名','MySQL密码') or die('数据库连接失败,错误信息:'.mysql_error());

// 第二步,选择指定的数据库,设置字符集
mysql_select_db(DB_NAME,$conn) or die('数据库错误,错误信息:'.mysql_error());
mysql_query('SET NAMES UTF8') or die('字符集设置错误:'.mysql_error());

// 显示数据

$searchs = $_POST['search']; //传递search框过来的值
$searchs= trim($searchs);

if (!$searchs) { echo '<div class="tips">注:搜索框不能为空.</div>'; exit; }
// $result = mysql_query($query) or die('SQL语句错误:'.mysql_error());

$result = mysql_query("SELECT * FROM 查询的表名 where 查询的字段名 like '%$searchs%'");
if (mysql_num_rows($result) < 1) echo '<div class="tips">没有数据</div>';

// 把结果集转换成数组赋值给$row,如果有数据为真
while(!!$row = mysql_fetch_array($result)){
echo"<tr><td>".$row["显示的第一个字段名称"]."</td><td>".$row["显示的第二个字段名称"]."</td><tr>";
}

// 断开数据库连接
mysql_close($conn);
?>
</table>
</center>

</form>
</body>
</html>