Hello,
I have been trying for the last few days to figure out how to get my search results to match full keywords that people search. For example in my database I have the names: Adam, Michael, James, David etc.
What is currently happening is if a user types the letter A and hits search, all names display because they contain the letter A. What I would like instead is if the user searches for just A then nothing should show. If someone searches for Dav then David should not show. I want it so that only if the keyword matches what is in the database should the result show.
I am totally new to php and have been using it for about 3 weeks. I am very familiar with html. I hope I have explained myself properly.
This is the code that I have so far:
<?php
if(!isset($q)){
echo '';
} else {
$query = mysqli_query($con, "SELECT * FROM videos WHERE active='1' AND title LIKE '%$q%' OR tags LIKE '%$q%' ORDER BY title");
$num_rows = mysqli_num_rows($query);
?>
<div class="search-wrap"><p><strong><?php echo $num_rows; ?></strong> results for <?php echo $q; ?></p></div>
<?php
while($row = mysqli_fetch_array($query)){
$id = $row['id'];
$title = $row['title'];
$date = $row['date'];
$tags = $row['tags'];
echo ' <h3>' . $title . '</h3> '
';
}
}
?>