在php和mysql中自动完成文本框 [英] auto complete text box in php and mysql

查看:50
本文介绍了在php和mysql中自动完成文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在php中创建一个自动完成的文本框。这是我的JavaScript代码



 <   script     src   =   assets / js / jquery-1.10.2.js >  < /   script  >  
< span class =code-keyword>< script src = assets / js / jquery-1.3.2.min.js > < / script >
< script src = assets / js / jquery-ui-1.10.4.custom.min.js > < / script >
< script type = text / javascript >
jQuery( document )。ready( function (){
$(' #search')。autocomplete({
source:' search-job.php'
minLength: 2
});
});
< / script >





这里是我的HTML代码

 <  输入    type   =  text    id   = 搜索    class   = 表格 - 控制输入-lg col-xs-4    name   =  search >  



这里是我的search-job.php



 <?php  
包括' connectdb.php'< /跨度>;
if(isset($ _ REQUEST [' term']))
< span class =code-keyword> exit
();
$ rs = mysql_query( select * from jobs where title` like'% .ugfirst($ _ REQUEST [' term'])。 %'ORDER BY id ASC LIMIT 0,10 die(mysql_error( ));
$ data = array();
while($ row = mysql_fetch_assoc($ rs,MYSQL_ASSOC)){
$ data [] = array(
' label' => $ row [' title'],
' value' => $ row [' title']
);
}
echo json_encode($ data);
flush();



我在search-job.php中获得了正确的值。但它没有被html捕获但是当我运行代码时没有发生任何事情?为什么会这样?



这就是它在网络标签上的样子



图片

解决方案

' #search')。autocomplete({
source:' search-job.php'
minLength: 2
});
});
< / script >





这里是我的HTML代码

 <  输入    type   =  text    id   = 搜索    class   = 表格 - 控制输入-lg col-xs-4    name   =  search >  



这里是我的search-job.php



 <?php  
包括' connectdb.php'< /跨度>;
if(isset(


_REQUEST [' term']))
exit ();


rs = mysql_query( 选择*来自`title`的工作,如'%'。ucfirst(


i`m trying to make a auto complete text box in php. here is my JavaScript code

<script src="assets/js/jquery-1.10.2.js"></script>
<script src="assets/js/jquery-1.3.2.min.js"></script>
<script src="assets/js/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function(){
$('#search').autocomplete({
source : 'search-job.php',
minLength:2
});
});
</script>



here is my html code

<input type="text" id="search" class="form-control input-lg col-xs-4" name="search">


here is my search-job.php

<?php
include 'connectdb.php';
if(isset($_REQUEST['term']))
exit ();
$rs=  mysql_query("select * from jobs where `title` like '%"  . ucfirst($_REQUEST['term']). "%' ORDER BY id ASC LIMIT 0,10") or      die(mysql_error());
$data=  array();
while($row=  mysql_fetch_assoc($rs,MYSQL_ASSOC)){
$data[]=array(
'label'=>$row['title'],
'value'=>$row['title']
);
}
echo json_encode($data);
flush();


i`m getting correct values in search-job.php. but it is not catching by html but when i run code nothing happened? why is that?

this is how it's looks on network tab

image

解决方案

('#search').autocomplete({ source : 'search-job.php', minLength:2 }); }); </script>



here is my html code

<input type="text" id="search" class="form-control input-lg col-xs-4" name="search">


here is my search-job.php

<?php
include 'connectdb.php';
if(isset(


_REQUEST['term'])) exit ();


rs= mysql_query("select * from jobs where `title` like '%" . ucfirst(


这篇关于在php和mysql中自动完成文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆