Creating search engine in php was so easy and joyful . The only thing needed is little understanding
mind and you should know php as well as sql . This script was based on an idea of how search engine works .
This script was the model based on google , yahoo , and other search engines.
FILES TO CREATE
1. db.php
2. seacrh.php
3. style.css
Creating Database For This Search Engine
1. First go to the phpMYadmin .
2. Create the database to insert the sql .
3. Click the sql link and paste the following sql lines.
CREATE TABLE search (
title TEXT NOT NULL ,
des TEXT NOT NULL
) ENGINE = MYISAM ;
INSERT INTO search(title , des) VALUES('Hallow world','hallow world test search engine');
INSERT INTO search(title , des) VALUES('The world is best ','zet , queen , cat , dog , horse');
INSERT INTO search(title , des) VALUES('title is best','Insert your description here');
title TEXT NOT NULL ,
des TEXT NOT NULL
) ENGINE = MYISAM ;
INSERT INTO search(title , des) VALUES('Hallow world','hallow world test search engine');
INSERT INTO search(title , des) VALUES('The world is best ','zet , queen , cat , dog , horse');
INSERT INTO search(title , des) VALUES('title is best','Insert your description here');
Replace the database host , database user , database password , database name with your database informations.db.php
<?php
$database_host = "localhost";
$database_user = "root";
$database_password = "";
$database_name = "test";
mysql_connect($database_host , $database_user , $database_password);
mysql_select_db($database_name);
?>
$database_host = "localhost";
$database_user = "root";
$database_password = "";
$database_name = "test";
mysql_connect($database_host , $database_user , $database_password);
mysql_select_db($database_name);
?>
search.php
<?php
include('db.php');
if(isset($_REQUEST['search'])){
$search_word = $_REQUEST['search'];
$sql = "SELECT * FROM search WHERE title LIKE '%$search_word%' OR des LIKE '%$search_word%'";
$q = mysql_query($sql);
$num = mysql_num_rows($q);
echo mysql_error();
if($num > 0){
echo '<div id="result">';
while($data = mysql_fetch_array($q)){
echo '<div id="boxer"><font color="blue">'.$data['title'].'</font><br>';
echo $data['des'].'</div><br><br>';
}
echo '</div>';
}
else echo '<center> DATA NOT FOUND ON THE SERVER </center>';
}
?>
include('db.php');
if(isset($_REQUEST['search'])){
$search_word = $_REQUEST['search'];
$sql = "SELECT * FROM search WHERE title LIKE '%$search_word%' OR des LIKE '%$search_word%'";
$q = mysql_query($sql);
$num = mysql_num_rows($q);
echo mysql_error();
if($num > 0){
echo '<div id="result">';
while($data = mysql_fetch_array($q)){
echo '<div id="boxer"><font color="blue">'.$data['title'].'</font><br>';
echo $data['des'].'</div><br><br>';
}
echo '</div>';
}
else echo '<center> DATA NOT FOUND ON THE SERVER </center>';
}
?>

No comments:
Post a Comment