Create a search engine like Google PHP codes

Create a search engine like Google

Lets make a search engine like Google

Today we will make a Google-like search engine with two small PHP codes and sweet MySQL.
First of all create a file called index.php:
<html> <head> <title>Title of your search engine</title> </head> <body> <form action='search.php' method='GET'> <center> <h1>My Search Engine</h1> <input type='text' size='90' name='search'></br></br> <input type='submit' name='submit' value='Search' ></br></br></br> </center> </form> </body> </html>

[Can customize your search engine name].

Now create another file called search.php:
<?php $button = $_GET ['submit']; $search = $_GET ['search']; if(!$button) echo "you didn't submit a keyword"; else { if(strlen($search)<=1) echo "Search term too short"; else{ echo "You searched for <b>$search</b> <hr size='1'></br>"; mysql_connect("localhost","your mysql username","password"); mysql_select_db("search"); $search_exploded = explode (" ", $search); foreach($search_exploded as $search_each) { $x++; if($x==1) $construct .="keywords LIKE '%$search_each%'"; else $construct .="AND keywords LIKE '%$search_each%'"; } $construct ="SELECT * FROM searchengine WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1. Try more general words. for example: If you want to search 'how to create a website' then use general keyword like 'create' 'website'</br>2. Try different words with similar meaning</br>3. Please check your spelling"; else { echo "$foundnum results found !<p>"; while($runrows = mysql_fetch_assoc($run)) { $title = $runrows ['title']; $desc = $runrows ['description']; $url = $runrows ['url']; echo " <a href='$url'><b>$title</b></a><br> $desc<br> <a href='$url'>$url</a><p> "; } } } } ?>

[Don't forget to edit MySQL connect above but like your host,username,password]

This time you enter your MySQL database and create a database named Search and create a table named searchengine which will have 5 columns.
  • Name the first column id type INT, index > primary and select Auto Incriminate. The next column is title, type varchar, length 100.
  • Then description > Text; url> Text; Save with keywords > varchar, length 100.
  • You go to the insert option and continue to index the web link with specific title, description, keywords..... Your chakham search engine is ready!
  • You might think, Is...will you ever be able to build an omen search engine like Google? Listen, you have more elaborate data in your head than Google's database, just import it in SQL (S=success; Q=quality; L=Legend) format!!!


Read More


Post a Comment

0 Comments