0

我想自动完成并从数据库中获取数据
这是我的代码:

<script src="js/jquery-1.9.1.js"></script>
<script src="js/jquery-ui.js"></script>
<script>
$(function() {
  $( "#tags" ).autocomplete({
    source: 'consultation/commande_tags.php'
  });
});
</script>


<form method="post" action="#" class="formstyle1">
<input type="type" name="piece_a_commander" id="tags" placeholder="Réference "  />
</form>

json页面

 <?php
    if($_GET["term"]){
    include "includes/connexion_bdd.php";
    $ref=mysql_real_escape_string($_GET["term"]); 
    $rq_tags="SELECT * FROM piece WHERE reference_p LIKE '%".$ref."%'  ";
    $ret_tags=mysql_query($rq_tags) or die (mysql_error());
    $array = array();
    while ($tab_tags=mysql_fetch_array($ret_tags)){ 
    array_push($array,$tab_tags['reference_p']);
    }
    echo json_encode($array );
    }

    ?>

我看不到任何建议,请帮我看看错误在哪里?

4

1 回答 1

0

试试这个代码:

代替

$().ready(function() {
 $( "#tags" ).autocomplete("consultation/commande_tags.php", {
    width: 108,
    matchContains: true,
    //mustMatch: true,
    //minChars: 0,
    //multiple: true,
    //highlight: false,
    //multipleSeparator: ",",
    selectFirst: false
});
});

联系 :

<?php
$host="localhost";
$user="root";
$pass="";
$bdd="paralel";

// connexion
$con = mysql_connect($host,$user,$pass)or die(mysql_error());

//selection bdd

$db = mysql_select_db($bdd,$con) 或死(mysql_error());

?>
于 2013-09-23T06:23:43.043 回答