javascript - using JQuery autocomplete from database with PHP (CodeIgniter) - Stack Overflow

So I want to use this plugin I want to retrieve all the user names from database using codeigniter then

So I want to use this plugin

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 autoplete. 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 :)

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

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 autoplete. 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 :)

Share Improve this question asked Mar 30, 2011 at 14:42 KayKay 2133 gold badges10 silver badges18 bronze badges 2
  • 3 Are you wanting us to write the code for you? Are you having trouble with something in particular? How about you give it a shot, and we'll help you along the way? – Jesse Bunch Commented Mar 30, 2011 at 14:44
  • I tried to do it, but I dont understand how to use a database with it. If its a simple var then OK, but getting from database is a bit difficult for me, I didn't entirely understand how to do it. – Kay Commented Mar 30, 2011 at 14:46
Add a ment  | 

1 Answer 1

Reset to default 4

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 Autoplete 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").autoplete('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 Autoplete Docs

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744990056a4604848.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信