Solved

php search box

Posted on 2013-01-09
24
218 Views
Last Modified: 2013-01-16
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
0
Comment
Question by:doctorbill
  • 12
  • 10
  • 2
24 Comments
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 500 total points
Comment Utility
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
0
 

Author Comment

by:doctorbill
Comment Utility
response to leakim971:
Do you have some working pages as examples please
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 500 total points
Comment Utility
you have a simple and basic demo button on the first, right click on it, choose view source
0
 

Author Comment

by:doctorbill
Comment Utility
I se the source but it accesses  "status.php" and " states_abbrev.php"  page.  Where is the code for these ?
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 500 total points
Comment Utility
Did you read the article?
0
 

Author Comment

by:doctorbill
Comment Utility
Sorry - I think I have now managed to get the information
0
 

Author Comment

by:doctorbill
Comment Utility
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
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
Comment Utility
We need to see what's wrong with your code, can you please show us ?
0
 

Author Comment

by:doctorbill
Comment Utility
Here is the edited code for my local database
rpc.php
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 500 total points
Comment Utility
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
 

Author Comment

by:doctorbill
Comment Utility
I get this:
There should be no direct access to this script!
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 500 total points
Comment Utility
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
 

Author Comment

by:doctorbill
Comment Utility
so what do I need to do
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 500 total points
Comment Utility
read the first link... the part you're looking for is : PDO version:
update your code
0
 

Author Comment

by:doctorbill
Comment Utility
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
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 500 total points
Comment Utility
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
 

Author Comment

by:doctorbill
Comment Utility
So I should place it in the head section between javascript tags ?
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 500 total points
Comment Utility
yes, after this line :
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
0
 

Author Comment

by:doctorbill
Comment Utility
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
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 500 total points
Comment Utility
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
 

Author Comment

by:doctorbill
Comment Utility
scripts attached - see above
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
Comment Utility
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
 

Author Closing Comment

by:doctorbill
Comment Utility
Working result
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now