I try to populate a auto-completed suggestion list box which fetch suggest keyword from a array and display as a drop down list.
Array
(
[0] => Array
(
[code] => 9BP3
[name] => 9Bp No3
)
[1] => Array
(
[code] => AA
[name] => Ataria
)
[2] => Array
(
[code] => AABH
[name] => Ambika Bhawani Halt
)
[3] => Array
(
[code] => AADR
[name] => Amb Andaura
)
[4] => Array
(
[code] => AAG
[name] => Angar
)
[5] => Array
(
[code] => AAH
[name] => Itehar
)
)
the keyword string will search on [name] value and print next suggested name in list items. Like;
echo ‘<ul class=”list”>’;
while($row = mysql_fetch_array($result))
{
$str = strtolower($row[‘name’]);
$start = strpos($str,$keyword);
$end = similar_text($str,$keyword);
$last = substr($str,$end,strlen($str));
$first = substr($str,$start,$end);
$final = ‘<span class=”bold”>’.$first.'</span>’.$last;
echo ‘<li><a href=’javascript:void(0);’>’.$final.'<…
}
echo “</ul>”;
I use ajax to send keyword value of the textbox as user type.
How to I build it ?