开发者

using JQuery autocomplete from database with PHP (CodeIgniter)

开发者 https://www.devze.com 2023-02-21 00:13 出处:网络
So I want to use this plugin http://docs.jquery.com/Plugins/autocomplete I want to retrieve all the user names from data开发者_如何学Gobase using codeigniter then store them in a var in javascript (I

So I want to use this plugin http://docs.jquery.com/Plugins/autocomplete

I want to retrieve all the user names from data开发者_如何学Gobase using codeigniter then store them in a var in javascript (If this is a good way) then use it in autocomplete. Also, I want the user if he/she enters any other text it wont be accepted, it has to be already stored in database only.

Thanx in advanced :)


OK, Here is how I would structure it:

First, you have to create a file to serve your data from your backend database. According to the jQuery Autocomplete Docs, your backend will need to return a list of options one per line.

Let's call our php file, get_results.php:

<?php

// Do your DB calls here to fill an array of results
$arrResults = array('option 1', 'option 2', 'option 3');

// Print them out, one per line
echo implode("\n", $arrResults); 

Then, in your JavaScript code, you'd do something like this:

$("#myTextBox").autocomplete('get_results.php');

That is the very basic of how I would do it. Hopefully, you can go from there. Here are some important resources:

  • PHP Basics
  • PHP Database Connections
  • jQuery Autocomplete Docs
0

精彩评论

暂无评论...
验证码 换一张
取 消