jQuery autocomplete from SQL database


In one of projects I should use auto complete (auto suggestion) functionality for faster data input. One of my colleges send me this link. Thanks to him I have made autocomplete field where you can chose one of 20K users!

I have modified rpc.php file because my database infrastructure is MS SQL 2008. Use this in rps.php file:

<?php include(“../conf.php”);

if(isset($_POST[‘queryString’])) {
$queryString = $_POST[‘queryString’];
if(strlen($queryString) >0) {
$dbhandle=mssql_connect($dbhost.($dbport ? ‘:’.$dbport : ”), $dbusr, $dbpwd) or die(“Nevaru pieslēgties datubāzei: ” . mssql_get_last_message());
mssql_select_db($dbname) or die(“Nevaru izvēlēties datubāzi!”);
$result = mssql_query(“[dbo].[autocomplete] ‘”.$queryString.”‘”, $dbhandle);
if (!$result) echo(“Kļūda (telpas) – $i: “.mssql_get_last_message().”<BR>\n<BR>\n”);
while ($arr = mssql_fetch_row($result)) {
echo ‘<li onClick=”fill(\”.$arr[0].’\’);”>’.$arr[0].'</li>’;
}
} else {
echo ‘There should be no direct access to this script!’;
}
mssql_close();
?>

If you need all code package, please let me know. Se screanshot of my form:

I cant find that tutorial because my keyword usage in google was slightly diferent.

If you cant find some simply things ask some friend to do it because google knows answers just use correct keywords!

Advertisements

About Kaspars

https://www.linkedin.com/in/kauzers
This entry was posted in Programming, Programming Kaspars and tagged , , , , , . Bookmark the permalink.

3 Responses to jQuery autocomplete from SQL database

  1. mahesh says:

    HI, I am looking for autocomplete combo box to fetchdata from MS SQL 2008. If you have sample could you please send it to my EMail “anap1.mahesh@gmail.com”. Thanks.

  2. karthik says:

    hi,
    I am looking for this exact same code for autocomplete in my college work php with sql. Please send this code that will be great.

    Karthik

  3. MJ says:

    Hi I realy like your page it helps alot.
    Appreciate it much if you can send me your code, thank you very much!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s