zid Posted April 26, 2014 Share Posted April 26, 2014 (edited) Hi guys, trying to acchieve a search query on mutiple tables using prepared statements and the query it self seems a bit confusing for me, have been searching and found the UNION feature but I still cannot get this to work. Please advice. pages - page.title - page.text posts - post.title - post.text This one works, single table using two rows: $stmt = $db->prepare("SELECT * FROM pages WHERE page_title LIKE :search_string OR page_text LIKE :search_string"); This one does not work with the UNION feature: $stmt = $db->prepare(" SELECT * FROM pages.page_title, WHERE pages.page_title LIKE :search_string UNION SELECT * FROM pages.page_text, WHERE pages.page_text LIKE :search_string UNION SELECT * FROM posts.post_title, WHERE posts.post_title LIKE :search_string UNION SELECT * FROM posts.post_text, WHERE posts.post_text LIKE :search_string "); And the bound: $stmt->bindValue(':search_string', '%'.$query.'%'); Edited April 26, 2014 by zid Quote Link to comment https://forums.phpfreaks.com/topic/288033-cannot-search-mutiple-tables/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.