Sometimes we need a simple search engine within our websites to find topics. Let me explain this with a simple example:
HTML codes for the form that will perform the search:
<form action="result.php" method="get">
<input type="text" name="searchquery" placeholder="Enter the keyword you want to search"><br>
<input type="submit" value="Search">
</form>
Codes to be included in result.php:
<?php
$searchquery = @mysql_real_escape_string($_GET['searchquery']);
$resultquery = @mysql_query("SELECT * FROM topics WHERE title LIKE '%".$searchquery."%'" );
if(@mysql_num_rows($resultquery)>0){
while($queryread=@mysql_fetch_array($resultquery)){
echo $queryread['title'].'<br>';
}
}
else{
echo 'Content Not Found';
}
?>
We select the data from the table named topics with the query SELECT * FROM topics, but there is a condition here WHERE title to specify that it should take the data in the title column, but here another condition is specified LIKE is the command used to search from the database LIKE '%searched word%' format, we put our variable holding the query from the form between % signs, then we use a while loop to print the found results one below the other, you can do this in a more beautiful way, you can define it as a link or you can do it with a nice design, I explained it to you in the simplest way.
If you have any questions, you can reach me by commenting below the topic.
Türkçe: https://niyazi.net/tr/php-site-ici-arama-motoru-yapimi
There are none comment