Welcome Guest, Not a member yet? Register   Sign In
Auto populate search in codeigniter using database
#1

[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" >
&lt;?php

$sql = "SELECT distinct details FROM drug_details";
$query = $this->db->query($sql);
$result = $query->result_array();

foreach ($result as $row) {
?&gt;
<option value="&lt;?php echo $row['details']; ?&gt;">&lt;?php echo $row['details']; ?&gt;</option>
&lt;?php
}
?&gt;
</select>

Direction:

<select name='direction_select' id="feedback">

</select>

&lt;/body&gt;
&lt;/html&gt;

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


&lt;?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>";

}

}
}
?&gt;

but this code is not working please anyone help me for this solution.
#2

[eluser]Tpojka[/eluser]
It's unreadable.
Use code tags to edit your post or link page with propper highlighting from this website.
#3

[eluser]InsiteFX[/eluser]
If you use POST REPLY instead of FAST POST you get the full editor!




Theme © iAndrew 2016 - Forum software by © MyBB