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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:49:17+00:00 2026-06-06T17:49:17+00:00

Here I am trying to implement the jQuery I have two main files one

  • 0

Here I am trying to implement the jQuery I have two main files one is db.php which hold this thing:

<?php

$connection = mysql_connect("localhost","root","");
$db = mysql_select_db("auto",$connection);

$sql = "SELECT * FROM data";

$result = mysql_query($sql,$connection);
//$arr = array();
while($row = mysql_fetch_array($result)){

echo $row['name']."\n";
}
//echo json_encode($arr);

mysql_close($connection);
?>

Then I have another file named as index.html in which I am calling jQuery functions:

<html>
<head>
<link rel="stylesheet" type="text/css" href="css/ui-lightness/jquery-ui-1.8.custom.css">
<link rel="stylesheet" type="text/css" href="css/autocomplete.css">
<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.8.custom.min.js"></script>
<script>

$(document).ready(function(){
    $("#example").autocomplete("db.php");
  });

</script>
</head>

<body>

Auto:<input id="example" type="text">

</body>
</html>

but I am unable to run any code can you tell me why? I am newbie to jQuery so apology for mistakes.

P.S: I tried with json encode function because I search and find out it may be reason of Json data (which I was assigning to $arr then echoing the jsonencode) but still its not working.

  • 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-06T17:49:18+00:00Added an answer on June 6, 2026 at 5:49 pm

    Ok Here is what i come up with the solution I am posting this in answer so that if any other person have problems using this can understand the basic without running around and messing head like me you can take this as a Short Simple Tutorial for Using a Jquery UI Autocomplete:

    First Make a Database Name auto in your mysql Server and Put this Dump Query in SQL or create a file named auto.sql and put all following content in that file and import it from phpmyadmin by going inside that database you just created i.e “auto”:

    -- phpMyAdmin SQL Dump
    -- version 3.5.1
    -- http://www.phpmyadmin.net
    --
    -- Host: localhost
    -- Generation Time: Jun 27, 2012 at 06:35 PM
    -- Server version: 5.5.24-log
    -- PHP Version: 5.3.13
    
    SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
    SET time_zone = "+00:00";
    
    
    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8 */;
    
    --
    -- Database: `auto`
    --
    
    -- --------------------------------------------------------
    
    --
    -- Table structure for table `data`
    --
    
    CREATE TABLE IF NOT EXISTS `data` (
      `name` varchar(30) NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    --
    -- Dumping data for table `data`
    --
    
    INSERT INTO `data` (`name`) VALUES
    ('fahim'),
    ('asim'),
    ('yasir'),
    ('jalil'),
    ('birdy'),
    ('gudu'),
    ('zalim'),
    ('papu'),
    ('ozair'),
    ('saima');
    
    /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
    /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
    /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
    

    Now make a Folder in your XAMPP or WAMP or any web server your using as auto and make following files and put their Contents in respective order:

    First File is db.php:

     <?php
    
        $connection = mysql_connect("localhost","root",""); 
    //make sure you change the hostname, username and password according to your setting
        $db = mysql_select_db("auto",$connection);
    
        $sql = "SELECT * FROM data";
    
        $result = mysql_query($sql,$connection);
        $arr = array();
        while($row = mysql_fetch_array($result)){
    
        $arr[] = $row['name']."\n";
        }
        echo json_encode($arr);
    
        mysql_close($connection);
    
    
        ?>
    

    Make another File with name index.php and put following content:

    <html>
    <head>
    <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/black-tie/jquery-ui.css" type="text/css" />
    <script src='http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js'></script>
    <script src='http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js'></script>
    <script>
    
    $(document).ready(function() {
            $( "#AC" ).autocomplete({
                source: "db.php"
            });
        });
    
    </script>
    </head>
    
    <body>
    
     <form>
         Text Box: <input id="AC" type="text" />
        </form>
    </body>
    </html>
    

    Another thing Notice i am using Online Google API to retrieve the Script Libraries and CSS file so make sure before testing this code you are connected to internet.

    Try to Run the Code it will Run Like a Charm :)….Its pretty simple for a newbie as well thats why i didn’t explained it…just a simple term i am getting data from database and make all that data echo in jason format because Jquery UI Auto complete require by default the Jason data!!

    Hope it helps 🙂


    Another thing i noticed that in firebug that whenever i type something This Autocomplete sends a Ajax request to the Db page from where i am getting the result and in that request it sends a variable name term so if i get that variable in the db.php file i can also use that into my SQL to retrieve Specific String because in above method it will show all the records retrieved from database so if i want to get only Specific terms like for example i put a word “fa” in the text box in the index.html file i want it retrieve only those name from the database which hold the string “fa” for that i can use that $_GET['term'] variable and put it in the SQL statement there i can use SQL LIKE operator to find a certain pattern i will update the db.php file as below:

    <?php
    
        $connection = mysql_connect("localhost","root",""); 
    //make sure you change the hostname, username and password according to your setting
        $db = mysql_select_db("auto",$connection);
    
        $sql = "SELECT * FROM data WHERE name LIKE '%".$_GET['term']."%'";
    
        $result = mysql_query($sql,$connection);
    
        //print_r ($result);
    
        $arr = array();
        while($row = mysql_fetch_array($result)){
    
        $arr[] = $row['name']."\n";
        }
        echo json_encode($arr);
    
        mysql_close($connection);
    
    
        ?>
    

    Now what i am doing i am saying to SQL get me the names which have the patter of string that $_GET['term'] is retrieving :)….!! T*his is simple Right* ??

    If you want to know more about LIKE operator Check This Link http://www.w3schools.com/sql/sql_like.asp

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

Sidebar

Related Questions

I am trying to implement this JQuery ImageBubbles that I found here: http://www.dynamicdrive.com/dynamicindex4/imagebubbles.htm However,
Trying to implement a search similar to here .This searches properties based on city,locality,property
I'm trying to implement this algorithm description from a previous question I had here
I'm trying to implement this example http://jsfiddle.net/gzF6w/1/ (from another question here on stak) on
I've been trying to implement the jquery validator that is the suggested answer here:
I'm trying to implement something like a photo carousel in jQuery. This carousel could
I'm trying to implement a 'fade into' script which would affect two images :
I am currently trying to implement the wonderful jQuery plugin 'week calendar' ( here
I am trying to implement auto complete via jquery auto complete plugin. I have
Here we go: Im trying to implement the timeago jquery plugin (http://timeago.yarp.com/) on my

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.