Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. public function search($searchTerm) {
  2. $db = Db::getInstance();
  3. $req = $db->prepare("SELECT p.postID, p.title, p.tagID, p.content, p.date, p.postImage, u.username "
  4. . " FROM user as u inner JOIN user_post as UP on u.userID=up.userID inner JOIN post as p "
  5. . "on up.postID=p.postID WHERE p.title LIKE CONCAT('%',:title,'%')");
  6. $req ->execute(array('title' => $searchTerm));
  7. $posts = [];
  8. foreach ($req->fetchAll() as $blogPost) {
  9. array_push($posts, new Post($blogPost['postID'], $blogPost['title'], $blogPost['tagID'], $blogPost['content'], $blogPost['date'], $blogPost['postImage'], $blogPost['username']));
  10. }
  11.  
  12. if (empty($posts)) {
  13. return null;
  14.  
  15. } else {
  16. return $posts;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement