douzong3599 2015-12-20 07:26
浏览 25

如何在php中使用ajax搜索关键字

Not showing any data from php into ajax. Any help would be appreciated.

HTML:

 Search Box:<input type="text" name="search" id="search">
 <div id="search1"></div>

AJAX:

        $("#search").keyup(function(){
        var search=$(this).val();
                 $.ajax({  //GR ID Generation
                  method: "GET",
                  url: "search_rep.php?invo="+search,
                })

                  .done(function( msg ) {
        $("#search").html(msg); 
        $("#search1").val();      
        }); 

PHP:

    $in  = mysql_real_escape_string($_GET['invo']);
    $msg = '';
    if(strlen($in) > 0 && strlen($in) < 20){
      $row = mysql_query("SELECT Bot_Name
                        FROM bot_info 
                        WHERE Bot_Name 
                        LIKE '%$in%'and  Bot_Type='Printed'",$con );
      while($result = mysql_fetch_array($row)){
        $msg .= $result['Bot_Name'] . "<br />";
      }
    }

Output should be shown as google search engine once You type a word automatic all sentences are shown regarding to that word.

  • 写回答

2条回答 默认 最新

  • duandao8607 2015-12-20 07:39
    关注

    You don't seem to be echoing any data out onto the page in PHP. Consider trying

    $in  = mysql_real_escape_string($_GET['invo']);
    $msg = '';
    if(strlen($in) > 0 && strlen($in) < 20){
      $row = mysql_query("SELECT Bot_Name
                        FROM bot_info 
                        WHERE Bot_Name 
                        LIKE '%$in%'and  Bot_Type='Printed'",$con );
      while($result = mysql_fetch_array($row)){
        $msg .= $result['Bot_Name'] . "<br />";
      }
    }
    echo $msg;
    

    You may also want to look at using MySQLi rather than the soon depreciated MySQL in PHP.

    If that fails to work, it may possibly be an issue with your database or another area of your code, let me know.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?