在使用自动填充功能并尝试检索$key
和$value
时,由于某种原因,我不知道发生了什么或我遗漏了什么,所以我可以在下拉列表中列出value
并使用该值的ID
,下拉是完全灰色的,我无法选择任何内容。这是一个例子。
jquery的
$(document).on('focus', 'div.form-group-options div.input-group-option:last-child input', function(){
var sInputGroupHtml = $(this).parent().html();
var sInputGroupClasses = $(this).parent().attr('class');
var sInputGroupId = $(this).parent().attr('id');
$(this).parent().parent().append('<div class="'+sInputGroupClasses+'">'+sInputGroupHtml+'</div>');
$('.searchsong').autocomplete({
source:'../includes/searchaddsong.php',
minLength:0,
});
});
searchaddsong.php
$key=$_GET['term'];
$sql = "SELECT ID,title FROM wafilepaths WHERE title LIKE '%{$key}%'";
$result = mysql_query($sql);
$rows = array();
while ($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
echo json_encode($rows);
如果我将mysql更改为$array[] = $row['title'];
,那么我会得到下拉列表中的值,但我也需要ID,所以我可以引用该记录。
任何帮助都会很棒。
答案 0 :(得分:0)
自动填充需要采用两种格式之一。标准索引数组,或格式为
[
{
label:"something",
value: "something"
},
....
]
你的title
和其他东西。只需在php中将title
和id
映射到label
和value
。
$row['label'] = $row['title'];
$row['value'] = $row['id']; //or whatever this field was
$rows[] = $row;