Auto populate search in codeigniter using database |
[eluser]Unknown[/eluser]
//This is my auto_populate.php controller <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); class auto_populate extends CI_Controller { private $dir = "search"; public function index() { $data['dir'] = $this->dir; $data['page'] = "auto_populate"; $this->load->view('main', $data); } } //this is my main page main.php <html lang="en"> <title>Learning Codeigniter</title> <head> <!-- Load All Resources (Js + CSS) here--> [removed][removed] [removed][removed] </head> <body> <?php include_once $dir . '/' . $page . '.php'; // include_once 'user/index.php'; ?> </body> </html> //this is my view file auto_populate.php <html> <head> </head> <body> <select id="select_option" > <?php $sql = "SELECT distinct details FROM drug_details"; $query = $this->db->query($sql); $result = $query->result_array(); foreach ($result as $row) { ?> <option value="<?php echo $row['details']; ?>"><?php echo $row['details']; ?></option> <?php } ?> </select> Direction: <select name='direction_select' id="feedback"> </select> </body> </html> //this is my registration.js file (function($) { $(document).ready(function($){ $('#select_option').change(function () { var username = $('#username').val(); if(username != "") { $.post('auto_submit_reg.php', { select_option: $("#select_option").val() }, function(response){ $('#feedback').html(response).show(); }); }else{ $.post('auto_submit_reg.php', { select_option: $("#select_option").val() }, function(response){ $('#feedback').html("<p>response</p>").show(); $("#select_option").val(""); }); } }); }); })(jQuery); //this is another page auto_submit_reg.php page which is called from registration.js file <?php if ($_POST) { $tab_name = mysql_real_escape_string($_POST['select_option']); if ($tab_name == "") { echo "<p>(*)Required Field Kept Empty !</p>"; }else { $sql = "select * from feeding_rule where tab_name='$tab_name'"; $query = $this->db->query($sql); $result = $query->result_array(); foreach ($result as $row) { echo "<option value='$row[details]'>$row[details]</option>"; } } } ?> but this code is not working please anyone help me for this solution.
[eluser]Tpojka[/eluser]
It's unreadable. Use code tags to edit your post or link page with propper highlighting from this website.
[eluser]InsiteFX[/eluser]
If you use POST REPLY instead of FAST POST you get the full editor! |
Welcome Guest, Not a member yet? Register Sign In |