嗨,伙计们,当我输入任何字母时,我在显示数据时遇到问题,没有数据可以完成任务,因此它没有从数据库中获取任何数据
控制器
<?php
//birds.php
class Birds extends CI_Controller
{
function index()
{
$this->load->view('birds_view');
}
function get_birds()
{
$this->load->model('birds_model');
if (!isset($_GET['term'])) {
$q = strtolower($this->input->get('term'));
$this->birds_model->get_bird($q);
}
}
}
- - - - - - - - - - 模型
//birds_model.php (Array of Strings)
class Birds_model extends CI_Model
{
function get_bird($q)
{
$this->db->select('birds');
$this->db->like('birds', $q, 'after');
$query = $this->db->get('birds');
if ($query->num_rows > 0) {
foreach ($query->result_array() as $row) {
$row_set[] = htmlentities(stripslashes($row['birds'])); //build an array
}
echo json_encode($row_set); //format the array into json data
}
}
}
- - - - - - - - - - - - - - - - - - - 看法
<html>
<head>
<link href="css/jquery-ui.css">
<script src=
"http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type=
"text/javascript"></script>
<script src="js/jquery-ui.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#birds").autocomplete({
source: "birds/get_birds" // path to the get_birds method
});
});
</script>
<title></title>
</head>
<body>
<form>
<input id="birds" type="text">
</form>
</body>
</html>
这是我的数据库
CREATE TABLE birds (
id INT NOT NULL AUTO_INCREMENT,
bird VARCHAR(50),
aka VARCHAR(50),
PRIMARY KEY (id)
) ENGINE = MYISAM ;
INSERT INTO birds (id, bird, aka) VALUES
(1, "Great Bittern", "Botaurus stellaris"),
(2, "Little Grebe", "Tachybaptus ruficollis"),
(3, "Black-necked Grebe", "Podiceps nigricollis"),
(4, "Little Bittern", "Ixobrychus minutus"),
(5, "Black-crowned Night Heron", "Nycticorax nycticorax"),
(6, "Purple Heron", "Ardea purpurea"),
(7, "White Stork", "Ciconia ciconia"),
(8, "Spoonbill", "Platalea leucorodia"),
(9, "Red-crested Pochard", "Netta rufina"),
(10, "Common Eider", "Somateria mollissima"),
(11, "Red Kite", "Milvus milvus"),
(12, "Hen Harrier", "Circus cyaneus"),
(13, "Montagu's Harrier", "Circus pygargus"),
(14, "Black Grouse", "Tetrao tetrix"),
(15, "Grey Partridge", "Perdix perdix"),
(16, "Spotted Crake", "Porzana porzana"),
(17, "Corncrake", "Crex crex"),
(18, "Common Crane", "Grus grus"),
(19, "Avocet", "Recurvirostra avosetta"),
(20, "Stone Curlew", "Burhinus oedicnemus");
我的数据库名称是鸟我的表名称是鸟我的问题是当我找不到任何数据库时