Tuesday, 17 November 2015

Search Box code in PHP

HTML Tags:

<form method="get" action="Search-Emp.php" class="navbar-form navbar-left" role="search">
<input type="text" name="name" class="form-control" placeholder="Search">
<input type="submit" name="submit" value="Search">
</form>
<br><br><br>
<table border=1>
<tr bgcolor="#CC99CC">
<th>Emp ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Image</th>
<th>Father Name</th>
<th>NIC</th>
<th>Phone Number</th>
<th>Address</th>
<th>Date Of Birth</th>
<th>Gender</th>
<th>Joining Date</th>
<th>Religion</th>
<th>Designation</th>
<th>Department</th>
<th>Working Status</th>
<th>Reg.No</th>
</tr>
</table>

PHP Code:


<?php
if (isset($_GET['name']))
{
$letter = $_GET['name'];
$A = mysql_connect("LocalHost","root","") or die("Error in MYSQL Connection!");
mysql_select_db("payroldb",$A) or die("Error in DataBase!");
$B = mysql_query("Select * from tblemp where FirstName like '%".$letter."%'",$A) or die("Error in Insert Query.");
$num_rows = mysql_num_rows($B);
if($num_rows == 1){
echo "<h2> $num_rows Employee </h2>";
}
else
echo "<h2> $num_rows Employees </h2>";
for($a=0; $a<$num_rows; $a++)
{
$rec = mysql_fetch_array($B);
echo "<tr>";
echo "<td>$rec[0]</td>";//EID
    echo "<td>$rec[1]</a></td>";//First Name
echo "<td>$rec[2]</td>";//Last Name
    echo "<td><img src='images/$rec[3]' width=50 height=50 border=5 Title='$rec[1]'></td>";//Image
echo "<td>$rec[4]</td>";//Father Name
echo "<td>$rec[5]</td>";//NIC
echo "<td>$rec[6]</td>";//Ph.No
echo "<td>$rec[7]</td>";//Address
echo "<td>$rec[8]</td>";//DOB
echo "<td>$rec[9]</td>";//Gender
echo "<td>$rec[10]</td>";//Joining Date
echo "<td>$rec[11]</td>";//Religion
echo "<td>$rec[12]</td>";//Designation
echo "<td>$rec[13]</td>";//Department
echo "<td>$rec[14]</td>";//Working Status
echo "<td>$rec[15]</td>";//Reg No                   
echo "</tr>";
}  
mysql_close($A);
}
?>


No comments:

Post a Comment