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

  • Home
  • SEARCH
  • 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 556789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:57:25+00:00 2026-05-13T11:57:25+00:00

Hello I am using autocomplete to allow users to search venues stored in a

  • 0

Hello I am using autocomplete to allow users to search venues stored in a MySQL database. The autocomplete plugin is currently listing the venues when the user begins typing and prints the selected venue using the result handler.

I would like to also print the address, phone number and website of the venue as well but I am not sure how to do this.

I have the autocomplete plugin running a php script to print out the venue names from the database. I am not sure how to retrieve the other fields in the database without displaying the autocomplete input field…

This is what I have so far:

JQuery

  $(document).ready(function(){
    $("#example").autocomplete("search.php", {width: 260, selectFirst: false}).result(function(event, data, formatted) {
    $("#result").html( !data ? "No match!" : "Selected: " + formatted);
    });

});

PHP

$search = $_GET['q'];
    $search = "%".$search."%";
    $result = mysql_query("SELECT club_name FROM clubs WHERE club_name LIKE '$search'") or die('Something is wrong');
        while($value = mysql_fetch_array($result)){
            $club = $value[club_name];
            echo "$club\n";
        }

The php above only select the club name because when I try to select more fields they display in the search results on the JQuery side.

I am new to JQuery so I am a little lost… Any suggestions?

  • 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-13T11:57:26+00:00Added an answer on May 13, 2026 at 11:57 am

    There are a few ways to do it, but this is the easiest:

    You want to return the data from the server like this. The first column should contain the value you want to retrieve in the end:

    title|address|phone|web
    title|address|phone|web
    title|address|phone|web 
    

    And then you want to use the formatItem and formatValue callback in your autocomplete function:

    $(document).ready(function(){
        $("#example").autocomplete("search.php", {
            width: 260, 
            selectFirst: false,
            formatItem: function(row){
              var ret = '<span class="title">' + row[0] + '</span><br />';
              ret += '<span class="address">' + row[1] + '</span> ';
              ret += '<span class="phone">' + row[2] + '</span> ';
              ret += '<span class="web">' + row[3] + '</span> ';
              return ret;
            },
            formatValue: function(row){
              return row[0]; // We only want the first value to be searched
            }
          }).result(function(event, data, formatted) {
            $("#result").html( !data ? "No match!" : "Selected: " + formatted);
          });
    });
    

    Also, your are not escaping the input from the user and as such have a nasty vunerability for SQL injection

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

Sidebar

Related Questions

Would it be possible to print Hello twice using single condition ? if condition
NOTE: Using .NET 2.0, and VS2005 as IDE Hello all, I'm working on logging
I'd like to create a basic Hello World style application for the IPhone using
I have the following line: 14:48 say;0ed673079715c343281355c2a1fde843;2;laka;hello ;) I parse this by using a
We are using PowerDesigner at work for database modelling. But there is a hell
Hallo, i am using WSS 3.0 and i need to display certain entries of
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Hello I was writing a Regular Expression (first time in my life I might
Hello can anybody solve this please I'm creating the object in the action class

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.