Guest User

Untitled

a guest
May 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.96 KB | None | 0 0
  1. <?php
  2.     session_start();
  3.     $sessionID=session_id();
  4.     $con = new mysqli(*, *, *, *);
  5.    
  6.     if (!$con){
  7.         die( print_r("Connect failed: %s\n", mysqli_connect_error()));
  8.     }
  9.     $searchparam=$_GET['search'];
  10.  
  11. ?>
  12.  
  13. <?php
  14.  
  15. $searchparam=str_replace(" ", "+", $searchparam);
  16. $searchparam="% " . $searchparam . " %";
  17. $searchparam=str_replace("+", " %+% ", $searchparam);
  18. $searchquery=explode("+",$searchparam);
  19. $x=count($searchquery)-1;
  20. $y=0;
  21. $paramcount='?';
  22. $types='s';
  23. while ($x>$y) {
  24.     $paramcount=$paramcount . ' OR (tags LIKE ?)';
  25.     $types=$types . 's';
  26.     $y++;
  27. }
  28. $title=array();
  29. $author=array();
  30. $date=array();
  31. $content=array();
  32. $tags=array();
  33. if ($stmt = mysqli_prepare($con, "SELECT title,author,date,content,tags FROM content WHERE tags LIKE " . $paramcount . " ORDER BY count DESC")) {
  34.                 array_unshift($searchquery, $stmt, $types);
  35.                 call_user_func_array('mysqli_stmt_bind_param',$searchquery);
  36.                 mysqli_stmt_execute($stmt);
  37.                 mysqli_stmt_bind_result($stmt, $titleFetched, $authorFetched, $dateFetched, $contentFetched, $tagsFetched);
  38.                 while (mysqli_stmt_fetch($stmt)) {
  39.                    $title[] = $titleFetched;
  40.                    $author[] = $authorFetched;
  41.                    $date[] = $dateFetched;
  42.                    $content[] = $contentFetched;
  43.                    $tags[] = $tagsFetched;
  44.                    
  45.                     }
  46.                 mysqli_stmt_close($stmt);
  47.             }
  48.            
  49. $x=0;
  50. foreach($tags as $tagsun) {
  51.   $tags[$x] = explode(" ", $tags[$x]);
  52.   $x++;
  53. }
  54. $x=0;
  55. foreach ($title as $titledis){
  56.  echo '<div class="blogpost">
  57.       <strong><h1 style="margin-bottom:5px;margin-top:5px;">' . $titledis . '</h1></strong>' . $author[$x] . '&nbsp;' . $date[$x];
  58.  echo '<br><br>' . $content[$x] . '<br><br>Tags: '; foreach($tags[$x] as $tagsecho) { echo '<a href="/search.php?search=' . $tagsecho . '">' . $tagsecho . '</a> '; } echo '<br></div>';
  59.  $x++;
  60. }
  61. if ($title[0]==$null) {
  62.  echo '<div class="blogpost">
  63.       <strong><h1 style="margin-bottom:5px;margin-top:5px;">No results returned</h1></strong></div>';
  64.  
  65.  
  66. }
  67. ?>
Add Comment
Please, Sign In to add comment