Advertisement
Guest User

Untitled

a guest
Feb 19th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. <?php
  2. $output = '';
  3. if(isset($_GET['q']) && $_GET['q'] !== ' ') {
  4. $searchq = $_GET['q'];
  5.  
  6. $q = mysqli_query($db, "SELECT * FROM article WHERE title LIKE '%$searchq%' OR content LIKE '%$searchq%'") or die(mysqli_error());
  7. $c = mysqli_num_rows($q);
  8. if($c == 0) {
  9. $output = 'No search results for <strong>"' . $searchq . '"</strong>';
  10. } else {
  11. while($row = mysqli_fetch_array($q)) {
  12. $id = $row['id'];
  13. $title = $row ['title'];
  14. $content = $row ['content'];
  15. $output .= '<a href="article.php?id=' .$id. '">
  16.  
  17. <h3>'.$title.'</h3></a>'.$content.'';
  18. }
  19. }
  20. } else {
  21. header("location: ./");
  22. }
  23. print("$output");
  24. mysqli_close($db);
  25.  
  26. <?php
  27. if(!empty($_GET['id']))
  28. {
  29. $sql = "
  30. SELECT id, title, content
  31. FROM article
  32. ";
  33. // then do the query, etc....
  34. }
  35.  
  36. $results = $db->query($sql);
  37.  
  38. if($results->num_rows) {
  39. While($row = $results->fetch_object()) {
  40. $title = htmlentities($row->title);
  41. $content = nl2br(htmlentities($row->content));
  42. echo "
  43.  
  44. <h2>{$row->title}</h2>
  45. {$row->content}
  46.  
  47.  
  48. ";
  49. }
  50. } else {
  51. echo 'No Results';
  52. }
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement