使用JQuery从数据库自动完成PHP(CodeIgniter) [英] using JQuery autocomplete from database with PHP (CodeIgniter)
问题描述
因此,我想使用此插件 http://docs.jquery.com/Plugins/autocomplete
So I want to use this plugin http://docs.jquery.com/Plugins/autocomplete
我想使用codeigniter从数据库中检索所有的用户名,然后将它们存储在javascript中的javascript(如果这是一个很好的方法),然后使用它在自动完成。
I want to retrieve all the user names from database 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在高级:)
Thanx in advanced :)
推荐答案
OK,这里是我的结构:
OK, Here is how I would structure it:
,您必须创建一个文件以从后端数据库提供数据。根据 jQuery自动填充文档,您的后端将需要返回一个选项列表每行一个。
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.
让我们调用我们的php文件get_results.php:
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);
然后,在您的JavaScript代码中,您可以这样做:
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
这篇关于使用JQuery从数据库自动完成PHP(CodeIgniter)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!