php search box

I have a dropdown box which is populated by a large number of list items
Can someone suggest a working php script that will carry out a predictive search when someone starts typing in the list box such that a list of possible values comes up after typing the first couple of characters
doctorbillTechAsked:
Who is Participating?
 
leakim971Connect With a Mentor PluritechnicianCommented:
my bad...

In states.php, replace :
                  $row_array['name'] = $row['name'];
by :
                  $row_array['value'] = $row['name'];

and in the javascript, replace :
$('#state_id').val(ui.item.code);
by :
$('#state_id').val(ui.item.value);
0
 
Lukasz ChmielewskiCommented:
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
doctorbillTechAuthor Commented:
response to leakim971:
Do you have some working pages as examples please
0
 
leakim971Connect With a Mentor PluritechnicianCommented:
you have a simple and basic demo button on the first, right click on it, choose view source
0
 
doctorbillTechAuthor Commented:
I se the source but it accesses  "status.php" and " states_abbrev.php"  page.  Where is the code for these ?
0
 
leakim971Connect With a Mentor PluritechnicianCommented:
Did you read the article?
0
 
doctorbillTechAuthor Commented:
Sorry - I think I have now managed to get the information
0
 
doctorbillTechAuthor Commented:
Response to Roads_Roads:
http://www.marcofolio.net/webdesign/a_fancy_apple.com-style_search_suggestion.html

I have been trying to adapt this for a local database but just cannot get it to work
Any help please
0
 
Lukasz ChmielewskiCommented:
We need to see what's wrong with your code, can you please show us ?
0
 
doctorbillTechAuthor Commented:
Here is the edited code for my local database
rpc.php
0
 
leakim971Connect With a Mentor PluritechnicianCommented:
your script return html instead a json object...

Autocomplete need something like this (here I put << ar >> in the textfield) :
http://www.jensbits.com/demos/autocomplete/states.php?term=ar

To see what your script return try your script by trying url to rpc.php directly in your web browser address bar :
http://your_site_web_address/path/to/your/application/folder/rpc.php?queryString=a
0
 
doctorbillTechAuthor Commented:
I get this:
There should be no direct access to this script!
0
 
leakim971Connect With a Mentor PluritechnicianCommented:
anyway your script return HTML and not a JSON object as you saw it in the first link :
<p id="searchresults">
<span class="category">foo</span>
<a href="sdksks.php">
<img src="search_images/pic.jpg" alt="" />
<span class="searchheading">dldldl</span>
</p>

Open in new window

0
 
doctorbillTechAuthor Commented:
so what do I need to do
0
 
leakim971Connect With a Mentor PluritechnicianCommented:
read the first link... the part you're looking for is : PDO version:
update your code
0
 
doctorbillTechAuthor Commented:
Comment from:
leakim971
http://www.jensbits.com/2010/03/29/jquery-ui-autocomplete-widget-with-php-and-mysql/

I have attached the files I have created from the website above but I keep getting the following error for the index page:

PHP Parse error: syntax error, unexpected '(', expecting T_VARIABLE or '$' in C:\Websites\Dreamweaver\Development\dev\jqueryexamples\jensBits_autocomplete_working_files\index.php on line 12

All the files reside in the same folder. Can someone help please
index.php
states.php
states-abbrev.php
0
 
leakim971Connect With a Mentor PluritechnicianCommented:
This is Javascript code, not php...
<?php
$(function() {
         
            $('#abbrev').val("");
                $("#state").autocomplete({
                source: "states.php",
                minLength: 2,
                select: function(event, ui) {
                    $('#state_id').val(ui.item.id);
                    $('#abbrev').val(ui.item.abbrev);
                }
            });
             
            $("#state_abbrev").autocomplete({
                source: "states_abbrev.php",
                minLength: 2
            });
        });
?>

Open in new window

0
 
doctorbillTechAuthor Commented:
So I should place it in the head section between javascript tags ?
0
 
leakim971Connect With a Mentor PluritechnicianCommented:
yes, after this line :
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
0
 
doctorbillTechAuthor Commented:
Here is the latest:
I have now managed to get the page working to the extent that when I type in more then 2 characters in the "State (abbreviaton in separate field): " text box (id=state),  the text box extends downwards by as much as the number of rows it is getting from the status.php page.

The problem is that these rows show no text but if I click on one of the rows the second text box (id = abbrev)  is populated but the "state" text box isn't

It is a real shame to have gone so far but not to get it working - any ideas please
index.php
states.php
0
 
leakim971Connect With a Mentor PluritechnicianCommented:
when I type in more then 2 characters in the "State (abbreviaton in separate field): " text box (id=state),  the text box extends downwards by as much as the number of rows it is getting from the status.php page

Thanks for this good news ! Yes,  you set :  minLength: 2, so it wiat for 2 chars !

please post your latests script or provide a link to see you page
0
 
doctorbillTechAuthor Commented:
scripts attached - see above
0
 
doctorbillTechAuthor Commented:
Working result
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.