NoteOnMe博客平台搭建
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

127 líneas
3.3 KiB

hace 3 años
  1. <?php
  2. require_once "pdo.php";
  3. session_start();
  4. if ( !isset($_POST['search']) ) {
  5. header('Location: index.php');
  6. }
  7. $stmt = $pdo->query("SELECT * FROM article ");
  8. while ( $row = $stmt->fetch(PDO::FETCH_ASSOC) ) {
  9. if($row['public']=="public")
  10. {
  11. $tmparray=explode($_POST['search'],$row['content']);
  12. $tmparray2=explode($_POST['search'],$row['headline']);
  13. $count=count($tmparray)+count($tmparray2);
  14. if($count>2){
  15. $result[]=array('content'=>$row['content'],'article_id'=>$row['article_id'],'headline'=>$row['headline'],'count'=>$count);
  16. }
  17. }
  18. }
  19. if(isset($result))
  20. {
  21. $count = array();
  22. foreach ($result as $res) {
  23. $count[] = $res['count'];
  24. }
  25. array_multisort($count, SORT_DESC, $result);
  26. }
  27. ?>
  28. <!DOCTYPE html>
  29. <head>
  30. <script src="js/jquery.min.js"></script>
  31. <script src="js/bootstrap.min.js"></script>
  32. <script src="js/setting.js"></script>
  33. <meta charset="utf-8"/>
  34. <meta http-equiv="X-UA-Compatible" content="ie=edge">
  35. <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
  36. <script src="js/jquery.singlePageNav.min.js"></script>
  37. <link rel="stylesheet" type="text/css" href="css/templatemo-style.css?t={{time()}}">
  38. <style type="text/css">
  39. .hidee{
  40. display:none;
  41. }
  42. </style>
  43. </head><body>
  44. <div class="fixed-header">
  45. <div class="container">
  46. <div class="navbar-header">
  47. <button type="button" class="navbar-toggle">
  48. <span class="icon-bar"></span>
  49. <span class="icon-bar"></span>
  50. <span class="icon-bar"></span>
  51. </button>
  52. <a class="navbar-brand" href="#">notebook</a>
  53. </div>
  54. <nav class="main-menu">
  55. <ul>
  56. <form class="form-inline" method="POST" action="search.php">
  57. <input class="form-control" type="text" name="search" placeholder="Search">
  58. <li><a href="personal_page.php?user_id=<?php if(isset($_SESSION["user_id"])){echo($_SESSION["user_id"]);}?>" class="external hidee">Home</a></li>
  59. <li> <a href="signup.php" class="hid external">注册</a></li>
  60. <li><a href="login.php" class="hid external">登录</a></li>
  61. <li> <a href="edit_article.php" class="hidee external">写新文章</a> </li>
  62. <li><a href="logout.php" class="hidee external">退出</a></li>
  63. </ul>
  64. </nav>
  65. </div>
  66. </div>
  67. <div class="container">
  68. <section class="col-md-12 content" id="home" >
  69. <div class="col-lg-12 col-md-12 content-item content-item-1 background">
  70. <ul style="margin-top:5em;" >
  71. <?php
  72. if(isset($result)){
  73. foreach( $result as $res ) {
  74. echo ('<li><a href="view.php?article_id='.$res['article_id'].'">');
  75. echo('<h1 class="section-title text-center dark-blue-text">');
  76. echo(htmlentities($res['headline']));
  77. echo("</h2></a> <p>");
  78. $article= substr($res['content'],0,300);
  79. echo(htmlentities($article));
  80. echo("</p></li><hr/>");
  81. }
  82. }
  83. else{
  84. echo('<h1 class="section-title text-center dark-blue-text">CREATE YOUR OWN....</h1>');
  85. }
  86. ?>
  87. </ul>
  88. </div>
  89. </section>
  90. </div>
  91. <div class="text-center footer">
  92. <div class="container"> NOTEBOOK</div>
  93. </div>
  94. </body>
  95. <script>
  96. var user_id = <?php if(isset($_SESSION['user_id'])) {echo($_SESSION['user_id']);}else{echo("null");}?>;
  97. if(user_id!=null)
  98. {
  99. $(".hidee").show();
  100. $(".hid").hide();
  101. }
  102. </script>
  103. </html>