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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:08:38+00:00 2026-05-27T22:08:38+00:00

I am having a weird problem with the autocomplete UI. I have searched on

  • 0

I am having a weird problem with the autocomplete UI. I have searched on here and I cannot find anything similar.

http://jsfiddle.net/TYPfw/ has the jquery and the HTML, here is the PHP.

$return_arr = array();
$param = mysql_real_escape_string($_GET['term']);
$fetch = mysql_query("SELECT * FROM customers WHERE company like '%$param%'"); 
while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) {
    $row_array['id'] = $row['id'];
    $row_array['company'] = $row['company'];

    array_push($return_arr,$row_array);
}

echo json_encode($return_arr);

The JSON comes out correctly, and when you type the first letter of a correct value, a TINY little (2px box) shows up under the input box, but if you type in something that doesnt exsist in the db, it goes away, but comes back when you are typing something that is.

I have used this similar code in many other projects and I have never run into this issue. Any thoughts about what I am missing? Been looking at this for too long for such a small task.

Image of box for reference.
https://i.stack.imgur.com/A8wnz.jpg

  • 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-27T22:08:39+00:00Added an answer on May 27, 2026 at 10:08 pm

    Sorry for my previous answer, I didn’t see the jsFiddle when I first read your question.

    The problem is that you’re not setting a value for the label property of the return array. The autocomplete functionality is expecting an array that contains objects that are either straight strings (["item1", "item2", "item3"]) or have a label property. The underlying autocomplete code uses the label property to know what to display. Check out jQuery-ui’s custom-data example to get a better idea of how your json ojbect should be formatted: http://jqueryui.com/demos/autocomplete/#custom-data

    Currently, your returned JSON would look something like this:

    [
      { id: "companyId", company: "company Name" },
      { id: "AnotherID", company: "another company" }
    ]
    

    However, you objects don’t have a label property. Changing your PHP to set the label (instead of company) as follows should fix the list not populating:

    $return_arr = array();
    $param = mysql_real_escape_string($_GET['term']);
    $fetch = mysql_query("SELECT * FROM customers WHERE company like '%$param%'"); 
    while ($row = mysql_fetch_array($fetch, MYSQL_ASSOC)) {
        $row_array['id'] = $row['id'];
        $row_array['label'] = $row['company'];
    
        array_push($return_arr,$row_array);
    }
    
    echo json_encode($return_arr);
    

    And, you’ll want to update your javascript to account for the new format:

    $(function() {
        $("#company").autocomplete({
            source: "bin/view_customers.php",
            minLength: 1,
            select: function(event, ui) {
                $('#id').val(ui.item.id);
                $('#company').val(ui.item.label);
            }
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having quite a weird problem here. I have just pasted the Yii folder
This is a really weird problem that I have been having. When I download
This is a weird problem I have started having recently. My team is developing
all. I'm having a bit of weird problem with client server program. I have
I'm having a weird problem with a threaded class using Boost::threads. Here is a
I am having a weird problem .. I have written a CUDA code which
Having a weird problem. I'm testing an ASP.NET application I wrote that queries SQL
I having a weird problem with Entity Framework with MySql database. Here's the code
i'm having an weird problem, my project have a login page, that's working, but
Having a weird problem here. Everybody knows that if you use web.config's customErrors section

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.