2016-01-24 103 views
2

这是我的第一页。下面是自动完成的:jquery自动完成返回数据

 <script> 
      $(function() { 
      $("#skills").autocomplete({ 
       source: 'search.php', 
        minLength:1, 
      select: function(event,ui){ *//autocomplete* 
       var code = ui.item.id; 
       if(code != '') { 

       } 
      } 
      }); 
      }); 
      </script> 

我的search.php页面

$query = $db->query("SELECT *  
         FROM patient 
         WHERE FirstName LIKE '%$searchTerm%' 
         OR MiddleName LIKE '%$searchTerm%' 
         OR LastName LIKE '%$searchTerm%' 
         OR PatientId LIKE '%$searchTerm%'"); 
    while ($row = $query->fetch_assoc()) { 
     $data[] = $row['FirstName']." ".$row['MiddleName']." ".$row['LastName']; 
     $id = htmlentities(stripslashes($row['PatientId'])); *//i want to pass this value* 
    } 
    //return json data 
    echo json_encode($data); 

我使用jQuery的自动完成。我想通过$id值回到第1页。我怎么能通过它?有人能帮我吗?

回答

0

只需添加具有标签和值的数组,每个项目

$label = $row['FirstName']." ".$row['MiddleName']." ".$row['LastName']; 
$value = htmlentities(stripslashes($row['PatientId'])); 
$data[] = array('label' => $label, 'value' => $value); 
+0

如果我添加此:( –

+0

你是什么意思,它不会搜索?你有试过吗?jQuery的自动完成功能支持这种格式也。 –

+0

是什么显示,如果我搜索的东西 –