Solved

php search box

Posted on 2013-01-09
24
222 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
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

776 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