Search is used in many websites.bigneers that enter in web development are facing a problem that how to make a search engine using php.now i try to solve this problem in simple way.(search in php,search suggestion in php,search engine in php)
Step 1: Cteate a html search box with submit button (index.php)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Search Using PHP</title>
</head>
<body>
<form action="search.php" method="post" >
<input type="text" name="search_box" />
<input type="submit" />
</form>
</body>
</html>
Step 2: Create search.php page
<?php
$keyword = explode(" ", $_POST["search_box"]);
$rs="select * from table_name where name LIKE '%".$keyword['0']."%' ";
for ($i=1; $i<count($keyword); $i++) {
$rs = $rs."AND name LIKE '%".$keyword[$i]."%' and name LIKE '%".$keyword[$i]."%' and name LIKE '%".$keyword[$i]."%' and product_name LIKE '%".$keyword[$i]."%'";
}
$rs=mysql_query($rs);
while($row=mysql_fetch_array($rs)){
echo $row["name"];
}
?>
Step 1: Cteate a html search box with submit button (index.php)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Search Using PHP</title>
</head>
<body>
<form action="search.php" method="post" >
<input type="text" name="search_box" />
<input type="submit" />
</form>
</body>
</html>
Step 2: Create search.php page
<?php
$keyword = explode(" ", $_POST["search_box"]);
$rs="select * from table_name where name LIKE '%".$keyword['0']."%' ";
for ($i=1; $i<count($keyword); $i++) {
$rs = $rs."AND name LIKE '%".$keyword[$i]."%' and name LIKE '%".$keyword[$i]."%' and name LIKE '%".$keyword[$i]."%' and product_name LIKE '%".$keyword[$i]."%'";
}
$rs=mysql_query($rs);
while($row=mysql_fetch_array($rs)){
echo $row["name"];
}
?>
No comments:
Post a Comment