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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:42:37+00:00 2026-06-11T12:42:37+00:00

I am using php and javascript to create a dynamicly populated autocomplete search engine

  • 0

I am using php and javascript to create a dynamicly populated autocomplete search engine for my wordpress site.

Example: user wants to search for “Nike Shoes” so they type in Nike Shoes into the search engine and they should see Nike Shoes as a suggestion after they type the first 3 letters.

I am having an issue where only the word Nike shows up as a suggestion. This happens with any terms you type into the search engine. Only the first word of the string will show up. I am sure it’s to do with the spaces in between words but not so sure on how to fix it.

Here is my code that is populating the autocomplete dynamically:

var availableTags = '<?php $result = mysql_query("select * from state"); 
                    $row = mysql_fetch_array($result); 
                    echo $row['name']; ?>'.split(" ");
                    $( "#title" ).autocomplete({
                    source: availableTags,
                    minLength: 3,
                    position: { my : "left top", at: "left top" },
                    appendTo: "#search-container"
                    });
                    });

I created this code from this site: http://www.tizag.com/mysqlTutorial/mysqlquery.php

If someone could please help me I would be very greatful.

Thanks,

Steve

  • 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-06-11T12:42:39+00:00Added an answer on June 11, 2026 at 12:42 pm

    I am using this function for auto suggest list. you can use it with slight modification

    function get_autosuggest_list($str=''){
    
            $q     = strtolower($str);
            $entry = array();   
            $i=0;
            if(!empty($q))
            {
                $entry[$i] = "A.fieldname like '".$q ."%'" ;
                $i++;
            }
    
            $sqlentry = "";
            $j=0;
            foreach($entry as $data)
            {
    
                if($j==0)
                $sqlentry  = " where ".$data;
                else
                $sqlentry .= " and ".$data;
    
                $j++;
            }
            $sql    = "SELECT DISTINCT field_name FROM `table` A ".$sqlentry." ";
            $query  = mysql_query($sql);
            $res    = mysql_fetch_array($query);
    
            foreach($res as $row)
            {
                $items = $row->fieldname;
                echo "$items\n";
            }
    
        }
    

    Usage:

    get_autosuggest_list(string);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How does one create Dynamic CSS and JavaScript On-The-Fly (using PHP). This needs to
I'm currently using PHP, JAVASCRIPT, MYSQL, XHTML, CSS to develop my site. Note that
I'm currently using PHP to dynamically create a javascript which will be echoed on
I have designed a webpage using HTML and client side validation using JavaScript.PHP for
How to load javascript contents using php. Suppose when php saves a file using,
I am using the stock SDK for php/javascript. Now the app I am building
I want to trigger javascript alert using PHP. Is it possible I want to
I want the value of JavaScript variable which i could access using PHP. I
I'm currently designing a web application using php, javascript, and MySQL. I'm considering two
I know how I would achieve this using PHP, but with jQuery / JavaScript

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.