Search Data From Database and Display the contents Proper Manner. | Sanwebcorner

Search Data From Database and Display the contents Proper Manner.

Search Data From Database and Display the contents Proper Manner using php and mysql:

This is one of the simple and effective Search Engine using php and my sql , Search the data from database and it will display the contents in a Proper way.

This is very useful for php beginners and using this simple search engine create your own search engine.

This is one of the simple code to search the data.

search concept using php

Program Code:

Mysql:

CREATE TABLE  `getinsearch`.`san` (
`companyname` VARCHAR( 150 ) NOT NULL ,
`address` VARCHAR( 350 ) NOT NULL ,
`contactnumber` INT( 200 ) NOT NULL ,
`mail` VARCHAR( 200 ) NOT NULL ,
`url` VARCHAR( 150 ) NOT NULL ,
`category` VARCHAR( 80 ) NOT NULL
) ENGINE = MYISAM ;
--------------------------------------------------------

head.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" />
<link rel="stylesheet" href="style.css" />
<title>Simple Working Search Engine Using Php</title>
<meta name="description" content="Simple Working Search Engine Using Php">

<meta name="keywords" content="Simple Working Search Engine Using Php


" />

<meta name="author" content="getinn">
<meta charset="UTF-8">

</head>

<body>
<div class="head">
<BR />
<marquee style="color:#FFFFFF; letter-spacing:1PX;">Simple Working Search Engine Using Php & My sql | Searching Data from database and display the result in a specified format.</marquee>

</div>
------------------------------------------------

index.php


<?php include('head.php')?>


<div class="center">
<center><a href="index.php"><img src="images/getinn.png" width="520" /></a></center>

<form action="search.php" method="get" >
<table border="0" cellpadding="0" cellspacing="0">
<tr>
    <td><input class="sansearch" type="text" name="query" id="text"   width="500px;" value="e.g. Getinn Infomedia Solution ,Gayathri Nagar" onfocus="if(this.value=='e.g. Getinn Infomedia Solution ,Gayathri Nagar')this.value=''" onblur="if(this.value=='')this.value='e.g. Getinn Infomedia Solution ,Gayathri Nagar'"  onkeyup="showResult(this.value)" style="text-align:center; color:#1A1A1A; letter-spacing:1px;"/>&nbsp;</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" id="search" value="Search" /></td>
</tr>
</table>
</form>

</div>



<?php include('foot.php')?>


----------------------------------------------

foot.php:



<div class="footer">
<br><br>
<p style="color:#FEFEFE; text-align:right; margin-right:80px;">Copyright &copy; 2014 | Powered by  &nbsp;<a href="http://www.sanwebtutorials.blogspot.in/">San Web Corner</a></p>
</div>

</body>
</html>

---------------------------

search.php:


<?php include('head.php')?>

<div>

<center><a href="index.php"><img src="images/getinn.png" width="620" /></a></center>
<form action="search.php" method="get" >
<table border="0" cellpadding="0" cellspacing="0">
<tr>
    <td><input class="sansearch" type="text" name="query" id="text"   width="500px;" value="e.g. Getinn Infomedia Solution ,Gayathri Nagar" onfocus="if(this.value=='e.g. Getinn Infomedia Solution ,Gayathri Nagar')this.value=''" onblur="if(this.value=='')this.value='e.g. Getinn Infomedia Solution ,Gayathri Nagar'"  onkeyup="showResult(this.value)" style="text-align:center; color:#000000; letter-spacing:1px;"/>&nbsp;</td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" id="search" value="Search" /></td>
</tr>
</table>
</form>
<br /><br />
<div  class="san">
<?php
 mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());

    mysql_select_db("getinsearch") or die(mysql_error());
 /*?>
mysql_connect("localhost", "root", "") or die("Error connecting to database: ".mysql_error());

    mysql_select_db("getinsearch") or die(mysql_error());
<?php */
?>


<?php
    $query = $_GET['query']; 
    $min_length = 1;
if(strlen($query) >= $min_length)
        $query = htmlspecialchars($query); 
        $query = mysql_real_escape_string($query);  
  
        $raw_results = mysql_query("SELECT * FROM san WHERE (`companyname` LIKE '%".$query."%') OR (`ADDRESS` LIKE '%".$query."%')") or die(mysql_error()); 
        if(mysql_num_rows($raw_results) > 0)
{
            while($results = mysql_fetch_array($raw_results))
             /*?> echo " &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;".$results['company name']."<hr size=5  color=#F2F2F2><img src=images/address-icon.png border=0>&nbsp;&nbsp;&nbsp;&nbsp;".$results['address']."<br><img src=images/contact-icon.png border=0>&nbsp;&nbsp; &nbsp;&nbsp;".$results['contact number']."<br>" ." <img src=images/email.png border=0>&nbsp;&nbsp;&nbsp;&nbsp;".$results['email']."<br>". " <img src=images/website-icon.png border=0>&nbsp;&nbsp;&nbsp;&nbsp;".$results['url']."<br>" ;
echo "<hr >"; <?php */  
echo"<p style='font-size:22px; color:#000000; line-height:5px;  font-weight:bold;'> {$results['companyname']}</p>";
echo"<hr size=5  color=#F2F2F2><img src=images/address-icon.png border=0>&nbsp;&nbsp;&nbsp;&nbsp;";
echo"{$results['address']}<br>";
echo"<img src=images/contact-icon.png border=0>&nbsp;&nbsp;&nbsp;&nbsp;";
echo"{$results['contactnumber']}<br>";
echo"<img src=images/email.png border=0>&nbsp;&nbsp;&nbsp;&nbsp;";
echo"{$results['mail']}<br>";
echo"<img src=images/website-icon.png border=0>&nbsp;&nbsp;&nbsp;&nbsp;";
echo"{$results['url']}<br>";
echo "<hr >";
            }
          
        }
        else{ 
            echo "<br>No results Found Please enter Your Address in below link";
        }   
    }
    else{ 
        echo "Minimum length is ".$min_length;
    }
?></div>
<br /><br />
<center><a href="insert.php">Insert Your Address Here</a></center>


</div>

<?php include('foot.php')?>

Download Code: