Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6834853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:09:44+00:00 2026-05-26T23:09:44+00:00

I am using jQuery autocomplete, and want to have a separate PHP file to

  • 0

I am using jQuery autocomplete, and want to have a separate PHP file to house the data, instead of creating a variable (i.e. var availableTags = [“Red”, “Orange”, “Yellow”, “Green, “Blue”]).

However, when doing this, the autocomplete will continually display all of the available options, and not filter out what the user types in.

Any ideas?

Javascript:

$(document).ready(function() {

    $( ".autocomplete" ).autocomplete({
            source: "../../db/autocomplete_list.php"
    });

});

autocomplete_list.php

require_once('../includes/connect.php');
$dbh = connect(DB_HOST,DB_USER,DB_PASSWORD,CM_DATABASE);

$colors = '[';

$sth = $dbh->query ("SELECT * FROM constants 
                     WHERE category='Colors' 
                     ORDER BY display");

while ($row = $sth->fetch ()) { 

    $colors.= '"'.$row[value].'", '; 

}

$colors = rtrim($colors, ', ');

$colors .= ']';

print $colors;

execution of autocomplete_list.php

[“Red”, “Orange”, “Yellow”, “Green, “Blue”]

EDIT:

Have updated my autocomplete_list.php file to the following. However, now the autocomplete isn’t displaying my values. If I check the response in FireBug, it is showing the results correctly, it just appears that they aren’t being passed back to the autocomplete.

require_once('../includes/connect.php');
$dbh = connect(DB_HOST,DB_USER,DB_PASSWORD,CM_DATABASE);

if(isset($_GET['term'])) {
    $mysearchString = $_GET['term'];
}

$sth = $dbh->query("SELECT category, value, display FROM constants 
                    WHERE category = 'COLORS' AND value LIKE '$mysearchString%'
                    ORDER BY display");

while ($row = $sth->fetch ()) { 
    print $row['display']."\n";         
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:09:45+00:00Added an answer on May 26, 2026 at 11:09 pm

    Found a solution here:

    http://www.jensbits.com/2010/03/29/jquery-ui-autocomplete-widget-with-php-and-mysql/

    require_once('../includes/connect.php');
    $dbh = connect(DB_HOST,DB_USER,DB_PASSWORD,CM_DATABASE);
    
    $return_arr = array();
    
    if(isset($_GET['term'])) {
        $mysearchString = $_GET['term'];
    }
    
    $sth = $dbh->query("SELECT category, value, display FROM constants 
                        WHERE category = 'COLORS' AND value LIKE '$mysearchString%'
                        ORDER BY display");
    
    while ($row = $sth->fetch PDO::FETCH_ASSOC()) { 
    
         $row_array = $row['display'];
    
         array_push($return_arr,$row_array);
    
    }
    
    echo json_encode($return_arr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using jquery-rails-autocomplete and want to have autocomplete on more than one column.
i have an input using the jquery autocomplete plugin. with this i want to
So I am using jquery.autocomplete.js, demo can be found here http://www.ajaxdaddy.com/demo-jquery-autocomplete.html I want to
I have being using jquery autocomplete. By default it is showing 10 items in
I'm using JQuery UI's autocomplete widget and would like to have access to the
I am using the jQuery autocomplete plugin and have wired up an input field
I am using jQuery autocomplete pluggin . I have the following code $().ready(function() {
I have a test server with a page using jquery autocomplete. The autocomplete feature
I'm using the jquery autocomplete UI widget, for example: var names = [John, Jack,
I am using jquery autocomplete combobox and everything is ok. But I also want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.