我正在使用 select2 插件从 mysql 填充标签。所以我将 q 变量传递给 getdada.php。但问题是
q 变量没有被传递给 getdata.php 。我想传递这个变量,以便我可以获得与之相关的数据(可能是我没有将 q 变量放在适当的位置。)
2.如果我不使用 q 变量,则只检索最后一个或第一个变量。我想将所有结果填充为标签数据(也许错误在我的 getdata.php 中的 jsoncode 格式中)
请帮忙。
$("#e8").select2({
placeholder: "Search for another Concept",
minimumInputLength: 1,
multiple: true,
ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
url: "getdata.php",
dataType: 'json',
data: function (term, page) {
return {
q: term, // search term
page: page
};
},
results: function (data, page) {
return { results: data};
}
}
});
这是getdata.php
$sql=mysqli_query($db3,"SELECT * FROM o4_tags" );
while($row=mysqli_fetch_array($sql)){
$tags=$row['tag_name'];
$id=$row['id'];
$myArray = array(
array( "id" => "$id", "text" => "$tags" ),
);
}
echo json_encode($myArray);