1

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

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? 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. Commented Mar 30, 2011 at 14:46

1 Answer 1

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 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:

Sign up to request clarification or add additional context in comments.

1 Comment

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.