drakor Posted August 5, 2016 Share Posted August 5, 2016 (edited) In my database I got table with keywords row.Keywords are separated by the commas(dog, black, German, white, dangerous).If I type single search term for example dog it will return result for dog however if i type two terms for example dangerous dog it returns 0 results.I want for my code to return results for multiple terms...Someone suggested explode the array of search words and do an OR condition in my query with the exploded array but I am a noob and don't know how to do it.Any help would be appreciated! My code is bellow. <?php if(isset($_POST['search'])){ $get_value = addslashes($_POST['search']); $search = mysqli_real_escape_string($con,"$get_value"); ?> <h2>Showing results for <?php echo $_POST['search'] ?></h2> <?php if($search==''){ echo "<center><b>Please write something in the search box!</b></center>"; exit(); } $result_query = "SELECT * FROM content WHERE keywords LIKE '%".$search."%'"; $run_result = mysqli_query($con,$result_query); // echo mysqli_num_rows($run_result); // exit; if(mysqli_num_rows($run_result)<1){ echo "<center>Sorry no matches found</center>"; exit(); } while($row_result=mysqli_fetch_array($run_result)) { $name=$row_result['name']; $keywords=$row_result['keywords']; $image=$row_result['image']; $link=$row_result['link']; ?> Edited August 5, 2016 by drakor Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted August 5, 2016 Share Posted August 5, 2016 Stuffing comma-separated values into a single column is wrong, and trying to do anything with this dabase layout is pretty much hopeless. Learn how to normalize your database, create a keyword table with one(!) keyword per row, and then we can help you. 1 Quote Link to comment Share on other sites More sharing options...
PravinS Posted August 8, 2016 Share Posted August 8, 2016 Full Text search may work for you Refer: http://dev.mysql.com/doc/refman/5.7/en/fulltext-search.html Quote Link to comment 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.