SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
;
;
;
;
CREATE TABLE `search` (
`id` int(11) NOT NULL DEFAULT '0',
`content` text COLLATE utf8_vietnamese_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_vietnamese_ci;
INSERT INTO `search` (`id`, `content`) VALUES
(666, 'cyg'),
(2, 'liwen'),
(555, 'liwen&cyg');
;
;
;
cyg.php
<?php
$link=mysqli_connect('localhost','root','','a');
mysqli_set_charset($link,'utf8');
$sql="select * from search";
$result=mysqli_query($link,$sql);
?>
<!--显示的效果-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table border="1" cellpadding="5">
<tr>
<td>id</td>
<td>标题</td>
<td>内容</td>
<?php
while ($row=mysqli_fetch_array($result)) {
?>
<tr>
<td><?=$row['id'];?></td>
<td><?=$row['content'];?></td>
</tr>
<?php
}
?>
<td><a href="create.php">创建才能排序哦</a></td>
<td><a href="asc.php">升序</a></td><!--从小到大-->
<td><a href="desc.php">降序</a></td><!--从大到小-->
</tr>
</table>
</body>
</html>
create.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="create.php" method="POST">
<input type="text" name="id">
<input type="text" name="content">
<input type="submit" value="提交">
</form>
</body>
</html>
<?php
if(!$_POST['content']||!$_POST['id'])
{
exit();
}
$content=$_POST['content'];
$id=$_POST['id'];
$link=mysqli_connect('localhost','root','','a');
mysqli_set_charset($link,'utf8');
$sql = "INSERT INTO search(id,content)
VALUES ('{$id}','{$content}')";
$result=mysqli_query($link,$sql);
echo "<script>alert('创建成功');</script>";
?>
<button><a href="cyg.php">返回</a></button>
asc:
<?php
$link=mysqli_connect('localhost','root','','a');
mysqli_set_charset($link,'utf8');
$sql = "SELECT id,content FROM search ORDER BY id";
$result=mysqli_query($link,$sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table border="1" cellpadding="5">
<tr>
<td>id</td>
<td>标题</td>
<td>内容</td>
<?php
while ($row=mysqli_fetch_array($result)) {
?>
<tr>
<td><?=$row['id'];?></td>
<td><?=$row['content'];?></td>
</tr>
<?php
}
?>
<td><a href="create.php">创建才能排序哦</a></td>
<td><a href="asc.php">升序</a></td><!--从小到大-->
<td><a href="desc.php">降序</a></td><!--从大到小-->
</tr>
</table>
</body>
</html>
desc.php
<?php
$link=mysqli_connect('localhost','root','','a');
mysqli_set_charset($link,'utf8');
$sql = "SELECT id,content FROM search ORDER BY id desc";
$result=mysqli_query($link,$sql);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<table border="1" cellpadding="5">
<tr>
<td>id</td>
<td>标题</td>
<td>内容</td>
<?php
while ($row=mysqli_fetch_array($result)) {
?>
<tr>
<td><?=$row['id'];?></td>
<td><?=$row['content'];?></td>
</tr>
<?php
}
?>
<td><a href="create.php">创建才能排序哦</a></td>
<td><a href="asc.php">升序</a></td><!--从小到大-->
<td><a href="desc.php">降序</a></td><!--从大到小-->
</tr>
</table>
</body>
</html>
|