Using this code, I do search from my database and display the result. Now its show all the result of my table first.
Then when I search for a new Item then its show the item. I do not want to display all result first. I want to display only searched Item.
<table class="table table-striped">
<tr>
<th>No</th>
<th>Teacher Name</th>
<th>Gender</th>
<th>Date of Birth</th>
<th>Place of Birth</th>
<th>Degree</th>
<th>Salary</th>
<th>Married</th>
<th>Phone</th>
<th>E-mail</th>
</tr>
<?php
$key="";
if(isset($_POST['searchtxt']))
$key=$_POST['searchtxt'];
if($key !="")
$sql_sel=mysql_query("SElECT * FROM teacher_tbl WHERE f_name like '%$key%' or l_name like '%$key%'");
else
$sql_sel=mysql_query("SELECT * FROM teacher_tbl");
$i=0;
while($row=mysql_fetch_array($sql_sel)){
$i++;
?>
<tr >
<td><?php echo $i;?></td>
<td><?php echo $row['f_name']." ".$row['l_name'];?></td>
<td><?php echo $row['gender'];?></td>
<td><?php echo $row['dob'];?></td>
<td><?php echo $row['pob'];?></td>
<td><?php echo $row['degree'];?></td>
<td><?php echo $row['salary'];?></td>
<td><?php echo $row['married'];?></td>
<td><?php echo $row['phone'];?></td>
<td><?php echo $row['email'];?></td>
</tr>
<?php
}
?>
</table>