我无法将数据库中的值分配给文本框

时间:2014-09-13 10:33:36

标签: php jquery mysql

我正在进行搜索操作,即按客户名称搜索客户。我有文本框,当在文本上键入第一个字母时,在jquery列表中自动完成功能所有与该字母匹配的客户名称。我们可以从中选择所需名称我希望在另一个文本框中获取客户表格客户表的ID。

我的表是客户

customer 

id    name

1      neenu

2      nitha

3      nisha

4       sitha

我有两页payment_verification.php和suggest_field.php

payment_verification.php

<script>
 function auto(tab,field,id){
 var point='#'+id;
 jQuery(document).ready(function(){
 $(point).autocomplete({source:'suggest_field.php?
 field='+field+'&table='+tab,    minLength:1});
  });
    }


 </script>   

 <input name="cust_name1" id="name" 
 onFocus="auto('customer','name','name')"     type="text" />

 <input name="cust_id" id="cust_id"    type="text"  vale=""/>

在自动功能中,第一个参数是表名,第二个参数是字段名,第三个参数是该文本框的id。

suggest_field.php

 <?php
 require_once("codelibrary/inc/variables.php");
 require_once("codelibrary/inc/functions.php");
 if ( !isset($_REQUEST['term']) )
 exit;
 $field=$_GET['field'];
 $table=$_GET['table'];


 $qry='select distinct '.$field.' from '.$table.'
 where '.$field.' like "'.     mysql_real_escape_string($_REQUEST['term']) .'%"  
 order  by '.$field.' asc';
 $rs = mysql_query($qry);
 $data = array();
 if ( $rs && mysql_num_rows($rs) )
 {
  while( $row = mysql_fetch_array($rs, MYSQL_ASSOC) )
   {
    $data[] = array(
        'value' => $row[$field]
    );
 }
}
echo json_encode($data);
flush();
 ?>

我在第一个文本框中输入了客户名称,我想在第二个文本框中获取客户的ID。 我的问题中的任何误解都很抱歉。

0 个答案:

没有答案
相关问题