Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function search($searchTerm) {
- $db = Db::getInstance();
- $req = $db->prepare("SELECT p.postID, p.title, p.tagID, p.content, p.date, p.postImage, u.username "
- . " FROM user as u inner JOIN user_post as UP on u.userID=up.userID inner JOIN post as p "
- . "on up.postID=p.postID WHERE p.title LIKE CONCAT('%',:title,'%')");
- $req ->execute(array('title' => $searchTerm));
- $posts = [];
- foreach ($req->fetchAll() as $blogPost) {
- array_push($posts, new Post($blogPost['postID'], $blogPost['title'], $blogPost['tagID'], $blogPost['content'], $blogPost['date'], $blogPost['postImage'], $blogPost['username']));
- }
- if (empty($posts)) {
- return null;
- } else {
- return $posts;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement