<?php
header("Content-Type: text/html; charset=utf-8");
// echo "测试";
$con=mysqli_connect("localhost:3307","root","","mydbone");
mysqli_query($con,"set names utf8");
if(!$con){
dis("ERROR:".mysql_error());
}
$sql="select * from news";
$result=mysqli_query($con,$sql);
$data=mysqli_fetch_all($result,MYSQLI_ASSOC);
// var_dump($data);
// var_dump(count($data));
$str='';
for ($i=0; $i <count($data) ; $i++) {
$str.="<div><p><a href='03_detail.php?id={$data[$i]["newsId"]}'>{$data[$i]['title']}</a></p>
<p> <span>{$data[$i]['author']}</span> <span>{$data[$i]['updateTime']}</span> </p>
<p>{$data[$i]['summary']}</p></div>";
}
$keyWord=isset($_GET['keyWord'])?$_GET['keyWord']:'';
$search="select * from news where title like '%{$keyWord}%'";
$res=mysqli_query($con,$search);
$searchResult=mysqli_fetch_all($res,MYSQLI_ASSOC);
// var_dump($searchResult);
$str='';
for ($i=0; $i <count($searchResult) ; $i++) {
$str.="<div><p><a href='03_detail.php?id={$searchResult[$i]["newsId"]}'>{$searchResult[$i]['title']}</a></p>
<p> <span>{$searchResult[$i]['author']}</span> <span>{$searchResult[$i]['updateTime']}</span> </p>
<p>{$searchResult[$i]['summary']}</p></div>";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>数据查询</title>
<style>
*{
margin: 0;
padding: 0;
}
html,body{
background-color: rgba(0,0,0,.1);
}
.container{
width: 1200px;
/*height: 95%;*/
margin: 20px auto;
/*border:1px solid red;*/
}
.container .showTitle{
float: left;
width: 65%;
/*height: 100%;*/
background-color: #fff;
box-shadow: 0 0 10px 5px rgba(0,0,0,.3);
margin: 0 20px;
/*padding: 10px;*/
}
.container .search{
float: left;
width: 30%;
height: 500px;
background-color: #fff;
box-shadow: 0 0 10px 5px rgba(0,0,0,.3);
}
.search form{
text-align:center;
margin-top: 50px;
}
.search form input[type="text"]{
width: 200px;
height: 20px;
padding: 5px;
}
.search form input[type="submit"]{
width: 50px;
height: 34px;
}
.showTitle div{
width: 90%;
/*height: 10%;*/
/*background-color: red;*/
margin: 0 auto;
padding: 10px;
border-bottom: 1px solid rgba(0,0,0,.1);
}
.showTitle div p a{
color: #000;
font-size: 20px;
display: inline-block;
margin: 10px;
}
.showTitle div p a:hover{
color: #2319DC;
}
.showTitle div p span{
display: inline-block;
margin-right:20px;
font-size: 15px;
color: rgba(0,0,0,.8);
}
.showTitle div p:last-child{
margin-top: 10px;
text-indent: 2em;
}
</style>
</head>
<body>
<div class="container">
<div class="showTitle">
<?php echo $str;?>
</div>
<div class="search">
<form action="04_fuzzyQuery.php" method="get">
<input type="text" name="keyWord" placeholder="请输入搜索标题">
<input type="submit" value="搜索">
</form>
</div>
</div>
</body>
</html>
PHP+mysql 登录注册查询
需积分: 11 187 浏览量
2017-10-25
16:20:29
上传
评论 4
收藏 45KB RAR 举报
...lemon_...
- 粉丝: 190
- 资源: 16