PHP, MYSQL Autocomplete does not working

前端 未结 4 1785
我在风中等你
我在风中等你 2021-01-28 04:16

I want to make auto complete text box for select employee names from the database. I don\'t have fair idea about that. But I tried to make it as following.

autocomplete

4条回答
  •  走了就别回头了
    2021-01-28 04:40

    // create search.php
    
    query("SELECT * FROM employee WHERE name LIKE '%".$searchTerm."%' ORDER BY name ASC");
    while ($row = $query->fetch_assoc()) {
        $data[] = $row['name'];
    }
    //return json data
    echo json_encode($data);
    ?>
    
    
    // SQL
    
    CREATE TABLE IF NOT EXISTS `employee` (
      `id` int(11) NOT NULL,
      `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL
    ) ENGINE=InnoDB AUTO_INCREMENT=26 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
    
    --
    -- Dumping data for table `employee`
    --
    
    INSERT INTO `employee` (`id`, `name`) VALUES
    (1, 'Ram'),
    (2, 'Ravi'),
    (3, 'Kumar'),
    (3, 'Aaathava'),
    (4, 'Sasi');
    
    // End
    
    
    
    
    
      
      Autocomplete textbox 
      
      
      
      
    
    
     
    

提交回复
热议问题