【问题标题】:AUSU jquery-Ajax Autosuggest Multiple valuesAUSU jquery-Ajax 自动提示多个值
【发布时间】:2012-07-26 12:25:47
【问题描述】:

我有一个包含以下字段的表单: 公司名, 地址, 城市

使用 AUSU jquery autosuggest 脚本,我可以根据在公司字段中完成的搜索来填充地址字段,但我似乎无法完成的是用适当的值填充城市字段。所有数据都存储在 mysql 数据库中。

我已经能够让地址和城市填充地址字段,但我需要这两个值进入各自的字段(shiptoaddress 和shiptocity)。

有什么建议吗?

这是我从mysql数据库获取数据的php:

    <?php 

    $con    =   mysql_connect("localhost","userid","password");
    if (!$con){ die('Could not connect: ' . mysql_error()); }
    mysql_select_db("dbase", $con);


    $id     =   @$_POST['id'];          // The id of the input that submitted the request.
    $data   =   @$_POST['data'];        // The value of the textbox.

 if ($id && $data)
{
    if ($id=='clients')
    {
        $query  = "SELECT shiptoaddress,company, shiptocity
                  FROM Clients
                  WHERE company LIKE '%$data%'
                  LIMIT 5";

        $result = mysql_query($query);

        $dataList = array();

        while ($row = mysql_fetch_array($result))
        {
            $toReturn   = $row['company'];
            $dataList[] = '<li id="' .$row['shiptoaddress'] .$row['shiptocity'] . '"><a href="#">' . htmlentities($toReturn) . '</a></li>';

        }

        if (count($dataList)>=1)
        {
            $dataOutput = join("\r\n", $dataList);
            echo $dataOutput;
        }
        else
        {
            echo '<li><a href="#">No Results</a></li>';
        }
    }
}
?>

这是html表单代码的一部分:

<script>
$(document).ready(function() {
    $.fn.autosugguest({  
           className: 'ausu-suggest',
          methodType: 'POST',
            minChars: 2,
              rtnIDs: true,
            dataFile: 'data.php'
    });
});
</script>
</head>
<body>
<div id="wrapper">
  <form action="index.php" method="get">
    <div class="ausu-suggest">
      <input type="text" size="100" value="" name="clients" id="clients" autocomplete="off" />
      <input type="text" size="100" value="" name="shiptoaddress" id="shiptoaddress" autocomplete="off"/>
      <input type="text" size="100" value="" name="shiptocity" id="shiptocity" autocomplete="off"/>


    </div>
  </form>

【问题讨论】:

    标签: mysql autosuggest


    【解决方案1】:

    我通过使用 Jquery 自动完成小部件解决了我的问题。

    【讨论】:

      猜你喜欢
      • 2011-11-14
      • 2018-10-09
      • 1970-01-01
      • 1970-01-01
      • 2013-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多