Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

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 in advanced :)

share|improve this question
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 Mar 30 '11 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 Mar 30 '11 at 14:46
add comment

1 Answer

up vote 3 down vote accepted

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:

share|improve this answer
 
THANX A LOT. Now THAT HELPED :D –  Kay Mar 30 '11 at 14:59
1  
No problem. One more thing: In codeigniter, you'll just use the MVC approach to get your data and display it. Create a controller, add a method called, say get_results, grab the data from your model, and use the controller to print it out using the method above. Easy peasy. Good luck! –  Jesse Bunch Mar 30 '11 at 15:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.