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 7077633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:26:52+00:00 2026-05-28T06:26:52+00:00

i’m struggling with jQuery autocomplete whole day. I cannot figure out how to connect

  • 0

i’m struggling with jQuery autocomplete whole day. I cannot figure out how to connect jQuery UI autocomplete with mysql database. I don’t know what should php file look like, how’s request sent to php etc.. In demos and documentation on jQuery site there is simple example with remote datasource where source is: source: “search.php”. So how search.php knows what i’ve typed in input box? there is no query attached to search.php :/ I’ve noticed that json is used.. i’m confused and i’ve tried dozen method without results. What i need is simple autocomplete with name of cities that contains text i’ve typed into textbox.

My db looks like:

table_cities:
-------------
id:   -city id
name: -city name

And i need autocomplete to show me cities that contains text i’ve typed into textbox e.g.

“po” will result in “liverpool” “Portsmouth”…

html
----
<input type="text" id="cities" />

js
--
$( "#cities" ).autocomplete({
...

Thanks!

  • 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-28T06:26:53+00:00Added an answer on May 28, 2026 at 6:26 am

    You just need to return a JSON-encoded array of id/value objects. The autocomplete plugin also sends over a get parameter named “q” which contains what is currently in the input box. A simple example of a search.php file that would work:

    $autocomplete_value = mysql_real_escape_string($_GET["q"]);
    $sql = "select id, name from table_cities where name LIKE '%$autocomplete_value%'";
    $query = mysql_query($sql);
    
    $results = array();
    while ($row = mysql_fetch_array($query, MYSQL_ASSOC)) {
        array_push($results, array('id' => $row['id'], 
                                   'value' => $row['name']) );
    }
    echo json_encode($results);
    

    You’ll need to adapt that to whatever PHP framework you might be using, but the pattern should be the same – loop through the results creating an array of ‘id’ and ‘value’ objects, then json encoding that.

    Edit: you might want to update the SQL to do lowercase compare (so capitalization is ignored) and other such enhancements, but this should at least get you going in the right direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I know there's a lot of other questions out there that deal with this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I don't have much knowledge about the IPv6 protocol, so sorry if the question
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string

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.