我在使用PHP的项目中创建了这个引导程序输入标记。如何使用自动完成功能将我的MySQL数据编码到Bootstrap输入标签中?
现在,我如何使用MySQL中的数据填充restrictTo
和suggestions
?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Send Memorandum</title>
<!-- Bootstrap -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/memo.css" rel="stylesheet">
<link href="css/bootstrap-tags.css" rel="stylesheet">
<script src="js/jquery.min.js"></script>
</head>
<body>
<form enctype="multipart/form-data" action="send.php" method="post" class="memo" style="padding-top:10px">
<div class="form-group row">
<div class="col-xs-8">
<label for="To" style="padding-top: 10px;" >To: </label><br>
<p>suggestOnClick</p>
<div id="suggestOnClick"></div>
</div>
</div>
</form>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap-tags.min.js"></script>
在本节我想使的建议默认值:被移除,然后用我的MySQL数据值,如“选择account_username FROM tbaccounts”入建议更换:和restrictTo:这是可能的?
所以这是我的脚本
<script>
$(function(){
$("#suggestOnClick").tags({
restrictTo: ["alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel", "india"],
suggestions: ["alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel", "india"],
promptText: "Click here to add new tags",
suggestOnClick: true
});
});
</script>
</body>
</html>
这是我的PHP
<?php
//fetch.php
$connect = mysqli_connect("localhost", "root", "", "fullcalendar");
$query = "
SELECT * FROM tbaccounts ORDER BY account_username
";
$result = mysqli_query($connect, $query);
$data = array();
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
$data[] = $row["account_username"];
}
echo json_encode($data);
}
?>
现在,我怎样才能把这个json_enccode($的数据);限制为:和Suggstions:在SuggestOnClick函数中?
只是做一个查询来获取标签和打印出来作为使用'json_encode JSON阵列()'。你的PHP在哪里?你做了DB查询吗? –
对不起@MagnusEriksson,但我不现在如何使用json_encode(),但你可以显示或帮助我如何做到这一点? 我有我的数据库名为fullcalendar,然后我想取我的表名为'tbaccouts'的数据tbaccounts有account_id,andaccount_username的数据。 account_username是我想要放在restrictTo和Suggestion脚本中的数据。 你能帮我解答吗? –
添加_all相关code_到您的问题。不要发表评论。这是不可读的。关于PHP函数的使用,首先检查[PHP手册](http://php.net/) –