이제 jq.ajax+php+mysql에 대한 키워드 퍼지 쿼리 구현에 대한 기사(예제 설명)를 공유하겠습니다. 좋은 참조 가치가 있으며 모든 사람에게 도움이 되기를 바랍니다.
이 기능은 기업에 매우 실용적이며 모든 사람에게 권장됩니다.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <style> *{margin:0;padding:0;} .text{width:200px;height:30px;line-height:30px;font-size:14px;outline:none;} ul{width:200px;height:auto;border:1px solid #999;border-top:none;} ul li{width:200px;height:30px;line-height:30px;font-size:14px;} li:hover{background:#ddd;} </style> <body> <input type="text" class="text" name="text"> <ul class="sea"></ul> <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.1.min.js"></script> <script type="text/javascript"> $(".text").bind("input", function() { if($(this).val().length>0){ search(); }else{ $(".sea").html(''); } }) function search(){ $.ajax({ type:"GET", url:"sea.php", data:{"text":$(".text").val()}, success:function(response){ //转换成json对象 eval("var json="+response); //console.log(json) var str=""; for(var i=0;i<json.length;i++){ str += "<li>" + json[i].sea + "</li>"; } $(".sea").html(str); } }) } </script> </body> </html>
<?php $con = mysqli_connect("localhost","username","password"); if(!$con){ echo "数据库链接失败"; exit; } mysqli_select_db($con,'jwhuang'); mysqli_query($con,'set names utf-8'); $text= isset($_GET['text']) ? trim($_GET['text']) : ''; $result=mysqli_query($con,"select * from search where sea LIKE '{$text}%' "); $search=array(); while($row=mysqli_fetch_assoc($result)){ //判断是否有对应的数据 if(!$row){ $search=''; exit; }else{ //对查询关键字进行标记 $row['sea'] = str_replace($text, '<font color="red">' .$text. '</font>', $row['sea']); $search[]=$row; } } echo json_encode($search); ?>
위 내용은 제가 모든 사람을 위해 편집한 것입니다. 앞으로 모든 사람에게 도움이 되기를 바랍니다.
js에서 로그인에 필요한 슬라이딩 검증을 구현하는 방법
Angular에서 드롭다운 상자 퍼지 쿼리 기능을 구현하는 방법
Nodejs의 암호화 모듈 보안 지식 정보(자세한 튜토리얼)
위 내용은 jq.ajax+php+mysql에서 키워드 퍼지 쿼리를 구현하는 방법의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!