search text box which will give me related data from database. |
[eluser]adiprogrammer[/eluser]
Please help me i have googled a whole for this day i am new to codeigniter. i want a search box which can be able to search in database, example : in college alumni site if there is table Names with ID fname 1 aditya 2 adi 3. bob 4 adam if i type in text box letter 'a' it should show me aditya ,adi,adam. please give me complete view, conntroller ,model and please tell me flow of code.
[eluser]Bart v B[/eluser]
Ok here is an example how it's done. I maded on a clean codeigniter installation so it's done in the welcome controller. Feel free to change it to you own controller, remember to change in the view this line: Code: $.ajax({ url: "<?php echo site_url('welcome/suggestions'); ?>", The controller: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); The model: Code: <?php Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> NOTE: You need to whipe the * out the script tags from the view. I can not post script tags here because they get removed.
[eluser]adiprogrammer[/eluser]
First of all Thanks a Ton Bart you are the only hope for me to do this code..:wow: i am not getting anything after view file after typing http://localhost/ftsearch/index.php it shows only text box not result. <b> i follow your code completely </b> I created submit button like Code: Submit :<input type="submit" name="mybtn"></input> Code: function GetAutocomplete($options = array()) But I am not getting anything . My questions are : 1.where to provide database name and table name in this code ( in my case DB name is alumni and table name is regnames ) 2.What happens after view exactly ..? I newbie to json and ajax. please help me and correct me . once again thanks for your your effords Bart.
[eluser]Bart v B[/eluser]
First of all you don't need a submit button ![]() Of you want to do more, but for the autocomplete you don't need it. here some explainations.. in application/config/database.php find these lines: Code: $db['default']['hostname'] = "localhost"; then change the line in /application/config/autoload.php Code: $autoload['libraries'] = array('database'); So this wil work right now ![]() Json and ajax is a little to complicated to explain in English for me. But what Json do, is crating an array like in php. Something like: Code: $foo = array('foo' =>'bar', 'some' =>'thing'); The javascript does a call to the controller in my example here: Code: $.ajax({ url: "<?php echo site_url('welcome/suggestions'); ?>", Mind, you need to whipe out this line: Code: $query = $this->db->get('autocomplete'); The database query looks like this: Code: $this->db->select('fname'); Hope this help you a little?
[eluser]adiprogrammer[/eluser]
woooooowwwwwwwww........>>> i am in the sky now :bug: Thanks a lot Bart.. you rock the world. This is my first post in any of the programming forum and i got reply from you.> Thanks a ton.. now my confidence to code in codeigniter is increased some % now i want to show this data on the same view Code: welcome_message.php i am working on it do u have any idea about this or any link . Please guide me in this.. you roxx man..
[eluser]skhan[/eluser]
hi Bart v B! I tried your MVC code for search button, but it seems javascript is not working even i already removed all asterisk (*) in script, and it shows the search textbox only and no button
[eluser]adiprogrammer[/eluser]
skhan you dont require button just follow code and settings given by given by Bart.
[eluser]saima[/eluser]
Hi, I am new in ajax and CI, I try to use this code but it didnt show data in input field it show only text box and display array on top of the page not in input field, wht should id do plz help me, i include all css and js thanx
[eluser]swgj19[/eluser]
It's ok to ask for help with a snippet of code that you provide, but asking for the entire code without lifting a finger is effortless and not real coding. I sure hope that all members of codeigniter will keep this unwritten rule of conduct when posting and that newcomers learn how to properly ask for help. Based on that, look at the tutorial http://video.derekallard.com/
|
Welcome Guest, Not a member yet? Register Sign In |