Hello guys i learn something new so i thought to share it with you people.This tutorial is about when you search some data in a search bar and as you enter any key word e.g 'a' so it start looking for keywords starting with 'a' and highlight it.In this way entering full name e.g ahmed it highlight the name ahmed.i used jQuery for this purpose and little bit of styling for the highlight purpose.i have used inline scripting for the purpose of ease for you people but prefer external scripting as it is the more proficient way.Here the code
<html>
<head>
<style type="text/css">
#table1, #table1 tr, #table1 td
{
border: 1px solid #666;
}
.highlight
{
background-color:#CCC;
}
</style>
<script type="text/javascript" src="jquery.js"></script> <!-- need jquery.js file-->
<script type="text/javascript">
$(document).ready(function(){
$("#search1").keyup(function(){
search2 =$(this).val();
$("#table1 tr td").removeClass('highlight');
if(jQuery.trim(search2) != ''){
$("#table1 tr td:contains('" + search2 +"')").addClass('highlight');
}
});
});
</script>
</head>
<body>
<?php
echo '<p>Search : <input type="text" id="search1" /></p>';
$connect = mysql_connect("localhost","root",""); // change here
mysql_select_db("project");
$limit = 14;
$last = 24;
$sql = mysql_query("SELECT `id`, `name` FROM `stu_info` WHERE `id` > '$limit' AND `id` < '$last'"); // change here
echo "<br /><table id='table1'>";
while($show = mysql_fetch_assoc($sql))
{
echo $id = '<tr id="test"><td>'.$show['id'].'<br /></tr></td>'; //change here
echo $name = '<tr><td>'.$show['name'].'</tr></td>'; //change here
}
echo "</table></p>";
?>
</body>
</html>