NoteOnMe博客平台搭建
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 
 

127 rader
3.3 KiB

<?php
require_once "pdo.php";
session_start();
if ( !isset($_POST['search']) ) {
header('Location: index.php');
}
$stmt = $pdo->query("SELECT * FROM article ");
while ( $row = $stmt->fetch(PDO::FETCH_ASSOC) ) {
if($row['public']=="public")
{
$tmparray=explode($_POST['search'],$row['content']);
$tmparray2=explode($_POST['search'],$row['headline']);
$count=count($tmparray)+count($tmparray2);
if($count>2){
$result[]=array('content'=>$row['content'],'article_id'=>$row['article_id'],'headline'=>$row['headline'],'count'=>$count);
}
}
}
if(isset($result))
{
$count = array();
foreach ($result as $res) {
$count[] = $res['count'];
}
array_multisort($count, SORT_DESC, $result);
}
?>
<!DOCTYPE html>
<head>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/setting.js"></script>
<meta charset="utf-8"/>
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<script src="js/jquery.singlePageNav.min.js"></script>
<link rel="stylesheet" type="text/css" href="css/templatemo-style.css?t={{time()}}">
<style type="text/css">
.hidee{
display:none;
}
</style>
</head><body>
<div class="fixed-header">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">notebook</a>
</div>
<nav class="main-menu">
<ul>
<form class="form-inline" method="POST" action="search.php">
<input class="form-control" type="text" name="search" placeholder="Search">
<li><a href="personal_page.php?user_id=<?php if(isset($_SESSION["user_id"])){echo($_SESSION["user_id"]);}?>" class="external hidee">Home</a></li>
<li> <a href="signup.php" class="hid external">注册</a></li>
<li><a href="login.php" class="hid external">登录</a></li>
<li> <a href="edit_article.php" class="hidee external">写新文章</a> </li>
<li><a href="logout.php" class="hidee external">退出</a></li>
</ul>
</nav>
</div>
</div>
<div class="container">
<section class="col-md-12 content" id="home" >
<div class="col-lg-12 col-md-12 content-item content-item-1 background">
<ul style="margin-top:5em;" >
<?php
if(isset($result)){
foreach( $result as $res ) {
echo ('<li><a href="view.php?article_id='.$res['article_id'].'">');
echo('<h1 class="section-title text-center dark-blue-text">');
echo(htmlentities($res['headline']));
echo("</h2></a> <p>");
$article= substr($res['content'],0,300);
echo(htmlentities($article));
echo("</p></li><hr/>");
}
}
else{
echo('<h1 class="section-title text-center dark-blue-text">CREATE YOUR OWN....</h1>');
}
?>
</ul>
</div>
</section>
</div>
<div class="text-center footer">
<div class="container"> NOTEBOOK</div>
</div>
</body>
<script>
var user_id = <?php if(isset($_SESSION['user_id'])) {echo($_SESSION['user_id']);}else{echo("null");}?>;
if(user_id!=null)
{
$(".hidee").show();
$(".hid").hide();
}
</script>
</html>