doushengyou2617 2010-12-02 00:07
浏览 51
已采纳

如何以简单的方式使用PHP + MySQL的新Jqueryui自动完成

I have searched almost a month everyday for this. In some cases they use the $.ajax way, in others the $.post way. In jqueryui demo page for autocomplete http://jqueryui.com/demos/autocomplete/ you can see they have a simple understandable way of grabbing the data to show it to the user. Now here comes my problem. Am trying to do a simple, short way of grabbing a list of names from a mysql table. this is what i have right now:

JS

$("#usuario").autocomplete({ source: "search.php", minLength: 3, select: function( event, ui ) {} });

PHP

$nameser = $_POST['usuario'];

$names = '';

$result = mysql_query("SELECT name FROM characters WHERE name LIKE '%$nameser%'");

while ($row = mysql_fetch_array($result)) { $names .= "$row[name]"."
"; }

echo $names;

if i send info from the input box to php it returns the search pattern answer correctly But how do i attach the returned information to the autocomplete in a simple way.

The jquery documentation does not provide a simple way of doing it to a php remote file.

  • 写回答

2条回答 默认 最新

  • duanpie2834 2010-12-02 00:28
    关注

    If you searched for a month and you haven't find anything that must be some kind of miracle searched 2 seconds find plenty of results

    http://www.ajaxdaddy.com/demo-jquery-autocomplete.html

    http://www.exploremyblog.com/html/blog_contents.php?blogid=300

    http://www.thewhyandthehow.com/jquery-autocomplete/

    there are millions of them for your code i would do something like this

      $(document).ready(function(){
        $("#example").autocomplete("./search.php");
      });
    

    try it

    $nameser = $_GET['q'];
    
    $names = '';
    
    $result = mysql_query("SELECT name FROM characters WHERE name LIKE '%".$nameser."%'");
    
    while ($row = mysql_fetch_array($result)) { $names .= $row[name]."
    "; }
    
    echo $names;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题