Jump to content

Php search help


drakor

Recommended Posts

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 by drakor
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.