/    Sign up×
Community /Pin to ProfileBookmark

How to search a string in array and populate dropdown list for autocompleted textbox?

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 ?

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@rootApr 14.2015 — If you want some kind of answer, you should repost your help request, wrap code and output in forum tags (see my signature for clue) and include more of the code you currently have, what you have posted is not a drop down but a list..!

As for searching strings, don't understand, you need to be more clear as to the format of the string, include examples. IMHO you should use minimal front end data, KISS is the order of the day and I am not talking about a bunch of guys in makeup and spandex suits.

You say you use AJAX, no evidence of it or its use in your code.
×

Success!

Help @bikash336 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...