【发布时间】:2012-09-14 11:28:24
【问题描述】:
我在这里遇到问题 我想使用自动完成显示数据库中的数据 但是当我在文本框中搜索时,它会显示所有内容 例如
c++javaphpcoldfusionjavascriptaspruby
但我想要的是
"c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"
这是我的代码
控制器
function get_ingredients() {
$this->load->helper(array('form', 'url'));
$this->load->library('form_validation');
$this->load->model("save_datas");
$data["show_ingre"] = $this->save_datas->select_ingredient();
$this->load->view("view_home", $data);
}
查看
<script>
$(document).ready(function() {
$("input#autocomplete").autocomplete({
source: ["<?php
foreach ($show_ingre as $ingre) {
echo "$ingre->ingredient";
}
?>"]
});
});
</script>
<?php echo form_open('home/save_input'); ?>
<input type="text" name="ingredient" id="autocomplete" /><br/>
<input type="submit" name="submit"/>
<?php form_close(); ?>
型号
function select_ingredient() {
$query = $this->db->query("SELECT ingredient FROM ingredients");
return $query->result();
}
【问题讨论】:
标签: php javascript codeigniter autocomplete