/search.php

https://github.com/joesteinkamp/Postia-CMS · PHP · 68 lines · 41 code · 23 blank · 4 comment · 10 complexity · f86e0aa9661801cc07baf1b9b6f87da8 MD5 · raw file

  1. <?php include 'objects/pullsettings.php'; // Retrieve settings ?>
  2. <?php
  3. $query = $_GET["q"];
  4. // If no query, give message
  5. if($query == "") {
  6. echo "Oops! You didnt search for anything. Make sure you type what you want to search in the search box above.";
  7. }
  8. // Perform Search
  9. include './objects/opendb.php';
  10. // Search Posts Table
  11. $result = mysql_query("SELECT * FROM $table_posts WHERE title LIKE '%$query%' OR content LIKE '%$query%' OR author LIKE '%$query%' ORDER BY timestamp DESC LIMIT 10") or die('Error : ' . mysql_error());
  12. while($row = mysql_fetch_array($result, MYSQL_NUM)) {
  13. list($id, $content, $timestamp, $author, $title) = $row;
  14. $content = stripslashes($content);
  15. $search_results .= '<div class="post">';
  16. if(!$title == "") { $search_results .= '<a href="post.php?id='.$id.'"><h3 class="title">'.$title.'</h3></a>'; } // If post has title, display it.
  17. $search_results .= '<div class="postcontent">'.$content.'</div>';
  18. $search_results .= '<div class="postmeta">'.$timestamp.' by <a href="user.php?user='.$author.'">'.$author.'</a></div>';
  19. $search_results .= '<div class="postnavs"><a href="post.php?id='.$id.'">View</a> | <a href="post.php?id='.$id.'#comment">Comment</a>';
  20. $user_role = getRole();
  21. $current_user = getCurrentUser();
  22. if($user_role == "3" || $current_user == $author) { $search_results .= ' | <a href="">Edit</a>'; }
  23. $search_results .= '</div>';
  24. $search_results .= '</div>';
  25. }
  26. // End Search
  27. include './objects/closedb.php';
  28. ?>
  29. <html>
  30. <head>
  31. <link rel="stylesheet" type="text/css" href="theme/<?php echo $theme; ?>/style.css" />
  32. <title><?php echo $site_name; ?>: Home</title>
  33. </head>
  34. <body>
  35. <div id="container">
  36. <div id="logonav">
  37. <?php include 'theme/'.$theme.'/logonav.php'; ?>
  38. </div>
  39. <div id="content">
  40. <h2>Search Results for "<?php echo $query; ?>"</h2>
  41. <?php echo $search_results; ?>
  42. </div>
  43. </div>
  44. </body>
  45. </html>