Solved

php search box

Posted on 2013-01-09
24
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 12
  • 10
  • 2
24 Comments
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 500 total points
ID: 38759777
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 38760583
0
 

Author Comment

by:doctorbill
ID: 38766674
response to leakim971:
Do you have some working pages as examples please
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 82

Assisted Solution

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

Author Comment

by:doctorbill
ID: 38766852
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
ID: 38766867
Did you read the article?
0
 

Author Comment

by:doctorbill
ID: 38767085
Sorry - I think I have now managed to get the information
0
 

Author Comment

by:doctorbill
ID: 38782427
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
ID: 38782444
We need to see what's wrong with your code, can you please show us ?
0
 

Author Comment

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

Assisted Solution

by:leakim971
leakim971 earned 500 total points
ID: 38782635
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
ID: 38782684
I get this:
There should be no direct access to this script!
0
 
LVL 82

Assisted Solution

by:leakim971
leakim971 earned 500 total points
ID: 38782706
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
ID: 38782718
so what do I need to do
0
 
LVL 82

Assisted Solution

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

Author Comment

by:doctorbill
ID: 38783386
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
ID: 38783424
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
ID: 38783658
So I should place it in the head section between javascript tags ?
0
 
LVL 82

Assisted Solution

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

Author Comment

by:doctorbill
ID: 38783932
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
ID: 38783950
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
ID: 38783975
scripts attached - see above
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 38784063
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
ID: 38784148
Working result
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

696 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